gmac / backbone.epoxy

Declarative data binding and computed models for Backbone
http://epoxyjs.org
MIT License
615 stars 89 forks source link

setBinding('attribute', {object: 'literal'}) doesn't do what you think... does it? #81

Closed disruptek closed 9 years ago

disruptek commented 10 years ago

Consider the following:

https://github.com/gmac/backbone.epoxy/blob/master/backbone.epoxy.js#L1189-1197

I can't see any reason not to perform this object wrap in every case. What am I missing?

disruptek commented 10 years ago

Just woke up and it came to me like a lightning bolt. :-)

What we're doing here is using the attribute to deduce the context. If the value looks like an object, we presume that the contents represent multiple attributes on the context and we set them. Otherwise, we simply assign the value to the same attribute referenced by the setBinding call. It's a tricky bit of overloading that really should be documented better. Let me know if you want me to take a crack at it.

gmac commented 9 years ago

LOL, "a tricky bit of overloading" pretty much sums up the entire Epoxy library. Binding magic definitely relies on dirty tricks. Sure, if you'd like to take a crack and better documentation, go for it.