mbest / knockout-freedom

Frees each binding from being updated by updates to its siblings.
14 stars 0 forks source link

what does this plugin do? #1

Closed mbest closed 11 years ago

mbest commented 12 years ago

This plugin will solve SteveSanderson/knockout#321 without having to use a fork of Knockout. This plugin will be compatible with versions 2.1 (current) and 2.2 (upcoming) of Knockout.

mbest commented 12 years ago

This plugin will replace ko.expressionRewriting.preProcessBindings (called ko.jsonExpressionRewriting.insertPropertyAccessorsIntoJson in v2.1) with a version that wraps each binding value in a function. This function will look like an observable, which will allow it to be "unwrapped" by ko.utils.unwrapObservable used in most bindings. Bindings that don't use unwrapObservable will need to be excluded. The following are the built-in bindings that use unwrapObservable:

The following don't use unwrapObservable:

The next part of this plugin will be to modify each of the supported bindings so that only init is used during the binding process. Each binding will get a new init function that will call the original init and update in a separate computed context. They will also get a new update function that will only call the original update function if this !== window; this is to prevent the function from being run by the binding processor, but to support directly calling the update function if needed.

mbest commented 12 years ago

To support two-way bindings, the function that wraps the binding values will also accept a single parameter, which it will pass on to the value if its an observable. If the value isn't an observable, it will support overwriting properties of the view model just like it's currently done in Knockout. To help optimize the plugin, the latter functionality will only be included for bindings that use it: value, selectedOptions, checked, and hasfocus.