Custom binding not firing unless I unwrap valueAccessor()

200 views
Skip to first unread message

Damien Sawyer

unread,
Jul 12, 2011, 9:02:02 PM7/12/11
to KnockoutJS
Hi,

I'm trying to learn KO and am a bit confused about something in a
custom binder.

Please have a look at the simple sample:
http://jsfiddle.net/damiensawyer/kkPhy/

If I comment out the following line, then the binding does not respond
to changes in the text boxes.
var valueUnwrapped = ko.utils.unwrapObservable(valueAccessor());

My understanding is that my custom binding should be data bound to
'Selected' via the label without any other dependencies. Can someone
please advise what I'm missing?

Thanks in advance,


Damien

rpn

unread,
Jul 12, 2011, 9:33:41 PM7/12/11
to knock...@googlegroups.com
Hi Damien-
Bindings are implemented using dependentObservables.  What this means is that any observables that have their value accessed while the binding is evaluated will become a dependency.  If that observable is updated, then the "update" function of the binding will run again.   So, there are some cases in a custom binding where you may have to access the value of an observable and then throw it away, just to create the dependency.

Additionally, a binding will have its update function run again, if another binding in the same data-bind attribute is triggered as well.

Damien

unread,
Jul 12, 2011, 11:14:20 PM7/12/11
to KnockoutJS
Thanks very much for that.
Reply all
Reply to author
Forward
0 new messages