ractivejs/ractive — pull request #1447 by evs-chris (2014-11-06 02:43:37+00:00)
Title: Per-element binding directives - RFC

Part of this is from #689, and part is something additional that I've wished for for a while.

### Per-element overrides
The first part is allowing a per-element override of `twoway` and `lazy`. This is handy for the occasional one-way field or field that needs to defer change events because the change handler is expensive (or something along those lines). I have a few forms that would benefit particularly from the latter.

```js
//
var ractive = new Ractive({
template: above,
lazy: false
});
// the first input is lazy, the second is not
```

### Laziness based on timeout instead of focus
Sometimes it's nice to be able to skip updates on every key press but still be able to get updates while the field is focused. This can mostly be done with a debouncer on the change event for a non-lazy field, but sometimes its nice to have an obvious indicator in the template. Also, a debouncer is going to fire once per {{timeout}}ms, whereas a timeout will fire {{timeout}}ms after the last key press. It's also very little code over the implementation of per-element overrides.

```js
//
var ractive = new Ractive({
template: above
});
// will fire 1000ms after the last keypress or on blur, whichever comes first
ractive.observe('foo', function(cur, prev) {
someExpensiveCalculation(cur, prev);
});
```

### Implementation/Breaking changes
This takes over attributes named `lazy` and `twoway` in `Element.prototype.init` to set appropriate properties on the element. Neither of those is an attribute in any html spec as far as I can tell, but that doesn't mean someone hasn't used one somewhere for some reason. So, it's potentially a breaking change since these are no longer available to elements outside of Ractive.