Closed mbest closed 11 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
:
visible
enable
disable
value
options
optionsCaption
(in v2.2)html
text
selectedOptions
css
style
checked
attr
hasfocus
with
if
ifnot
foreach
template
The following don't use unwrapObservable
:
click
event
<event>Bubble
submit
valueUpdate
optionsValue
optionsText
optionsIncludeDestroyed
(v2.2)uniqueName
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.
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
.
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.