mikeric/rivets — pull request #80 by mikeric (2012-10-22 00:40:49+00:00)
Title: Advanced custom binders API

This pull-request implements a more flexible API to define custom binders. All previously "special bindings" are now placed in rivets.routines along with all other binders/routines and their logic is completely self-contained.

Some of the features added in the new custom binders API:

- Wildcard matchers for routine identifiers like `each-*` or `class-*` (arguments are accessible in `binding.args`).
- Routines (binders in **0.4.x**) can now be defined as an object to allow specifying the following additional binding properties:
- `bind`: (function) This function will get called on `binding.bind()`. Use it to store some initial state on the binding, or to set up any event listeners on the element (used in value, checked, unchecked, iteration).
- `unbind`: (function) This function will get called on `binding.unbind()`. Use it to reset any state on the element that would have been changed from the routine getting called, or to unbind any event listeners on the element that you've set up.
- `block`: (true or false) Blocks the current node and child nodes from being binded (used for iteration binding).
- `publishes`: (true or false) Set this to true if you want `view.publish()` to call publish on these bindings (used for value, checked, unchecked, and any other bidirectional binder).
- `function`: (true or false) Set to true if the value of this binding is meant to be used as a function. This tells the binding not to execute the function before passing it through the formatters (used in the `on-[event]` binding).
- `routine`: (function) This is the routine function, it gets called when an observed attribute changes. This is no different from the way routines work in **<= 0.3.12**. The routine is actually optional now, for example if your binding only reacts to element changes (one-way binding from el to model), then you can leave this out.
- All above functions defined on the binder will be called in the context of the `Rivets.Binding` instance, so you can access all properties on the binding from `this` / `@`.