ampersand-dom-bindings icon indicating copy to clipboard operation
ampersand-dom-bindings copied to clipboard

Borrow features from Backbone.Epoxy

Open markerikson opened this issue 10 years ago • 0 comments

Been working on a Backbone app for the last year, and Ampersand looks like it solves a lot of the issues I've run into. I've been using the Backbone.Epoxy plugin, which has enhanced Model and View classes.

Epoxy.View has a lot of very useful abilities, and I think it would be helpful if Ampersand-Dom-Bindings borrowed a few of those. The biggest ones I see are:

  • More binding types. Epoxy includes several binding types (which it refers to as "handlers") for form fields, checkboxes, and option dropdowns, as well as a "css" handler. Note that several of Epoxy's handlers are trivial implementations using jQuery. Also, one none-Epoxy binding type suggestion: a binding that will swap classes based on the value of a model attribute, not just its truthiness. I see a "switchClass()" function in Ampersand-Dom, so that would seem pretty simple to implement.
  • Epoxy also has "binding filters", which allow various formatting of values after they are retrieved from a model.
  • Most importantly, EXPANDABILITY. Epoxy comes with a variety of handlers and filters included, but custom handlers and filters can be defined either locally in your Epoxy.View subclass, or added to the global list. Being able to define your own custom binding handlers is extremely helpful.
  • Finally, Epoxy has a custom mini-language for defining bindings. Example:
<a data-bind="text:linkText,attr:{href:linkUrl,title:linkText}"></a>

If you look way down under the hood, it's actually using the JS "with()" syntax to do dynamic lookup of model fields, which is probably a little too magical. Still, the shorthand syntax is kind of nice.

markerikson avatar Aug 28 '14 03:08 markerikson