Coder Social home page Coder Social logo

Attribute Binding about plates HOT 11 CLOSED

flatiron avatar flatiron commented on June 12, 2024
Attribute Binding

from plates.

Comments (11)

mwawrusch avatar mwawrusch commented on June 12, 2024

I don't like this one, reason is that it requires a transformation of the typical json that you receive from rest. What about the following:

data-bind, name, id for the default one

and data-bind-href, data-bind-src, etc for specific overrides. Using this approach it is possible to have flat json input and map that directly to the markup without any transform.

from plates.

appinsanity avatar appinsanity commented on June 12, 2024

My apologies, I should have used gist for the code, here is a sample of attribute binding, where data-attributeName is used to map JSON to attributes, no modification to the JSON data is necessary.

https://gist.github.com/1364192

from plates.

mwawrusch avatar mwawrusch commented on June 12, 2024

Ha funny, seems we had almost an identical idea :).

I do think though that it needs to always start with data-bind- otherwise you would end up interfering with existing html that uses data- to drive javascript functionality.

from plates.

appinsanity avatar appinsanity commented on June 12, 2024

good point, do you have a link where data- is used to drive js functionality?

from plates.

mwawrusch avatar mwawrusch commented on June 12, 2024

Don't have a link for that, but I have seen it in the wild and use it myself. For example I some where use it like this:

This of course has huge benefits, you are really able to decouple programming code from the visual aspects, and change functionality without actually touching code.

I think I need to blog about this some day.

from plates.

appinsanity avatar appinsanity commented on June 12, 2024

Martin,

This brings up a couple of good points, in my implementation the attribute data-bind="person" is removed during the template render, consider the syntax data-text="name" when you are binding to for example an a tags anchor text, I kinda like this as it's more explicit and allows for a data-bind and a data-text to live on the same html tag, I believe I had one case where this was necessary.

I do like the cleanliness of syntax like data-href=""... the rule would be something like if it's not data-bind or data-text then the format data-attributeName is assumed. In the case of data-href="" since it's replaced with href="" during the render process you would not have collisions.

Still thinking on this one...

Mike

from plates.

jfhbrook avatar jfhbrook commented on June 12, 2024

+1 for a way to bind attributes. There needs to be a way to modify attributes such as href.

from plates.

mwawrusch avatar mwawrusch commented on June 12, 2024

appinsanity: Removing the binding information from the html would be problematic for me as I use it to write data back into models when in the browser. Flow is like this: Load model from server, create html through plates from model, on update of value (keystroke, click) update model.

I do think that anything binding related should start with data-bind, it makes it clear to plates and the casual reader that data binding is taking place. If a developer encounters a tag like data-href= intent would not be immediately clear, with data-bind-href it would be obvious though.

In any case, we need this fast. At least I do :)

from plates.

appinsanity avatar appinsanity commented on June 12, 2024

Martin,

What do you think of this syntax for data-bind:

<a data-bind="href:url, text:title"></a>

<script>
var data = {
    title: "gitgub",
    url: "https://github.com/"
}
</script>

With this syntax data-bind would be removed during the render process, but you could re-inject additional data-bind or data-tweets-from-user etc...

Mike

from plates.

mwawrusch avatar mwawrusch commented on June 12, 2024

Hi Mike, not a friend of this, to be honest. this adds a lot of complexity and removes understandability. Knockout.js seems to have a similar problem. I had a bit of a rough day, but I am working on the reverse (binding from dom to models) thursday, which should give some more insights.

from plates.

heapwolf avatar heapwolf commented on June 12, 2024

done. it works like this...

  var html = '<span></span><img id="bar" class="foo bazz" src=""/>';
  var data = { "bazz": "Hello, World" };

  var options = { "bazz": ["class", "src"] };

  var output = Plates.bind(html, data, options);

from plates.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.