Dev Blog

Typical title for developers blog. Contains boring things.

Knockout JS offers
manual subscribing to observables, so that arbitrary code can
be executed whether the observable value changes. This might be
useful to update user interface when value changes, or to perform
AJAX requests based on value of observable. For instance filters
can be implemented, which will pull new data according to
observable value.

When using bare KnockoutJS the observable itself is object having
method subscribe. Example of subscribing in bare KO:

However, when using
EcmaScript 5 plugin, which allows using observables without
parenthesis, the subscribe method is not available.
The value of active field would appear as a plain
JavaScript type, for instance boolean value. Luckily the
KO have the method to obtain real observable with
ko.getObservable where first parameter is view
model, the latter one is observable name. The resulting code is a
bit different that that from the bare KnockoutJS in terms of
getting access to subscribe method: