I've written a few custom bindings using KnockoutJS. I'm still unsure when to use ko.utils.unwrapObservable(item)
Looking at the code, that call basically checks to see if item
is an observable. If it is, return the value(), if it's not, just return the value. Looking at the section on Knockout about creating custom bindings, they have the following syntax:
var value = valueAccessor(), allBindings = allBindingsAccessor();
var valueUnwrapped = ko.utils.unwrapObservable(value);
In this case, they invoke the observable via ()
but then also call ko.utils.unwrapObservable
. I'm just trying to get a handle on when to use one vs. the other or if I should just always follow the above pattern and use both.