{{ title }}
{{/if }} {{# ifnot: body }}Tracking array changes
Since Knockout 3.0
there has been an arrayChange
event that can be attached to an observable
or observableArray
.
One subscribes to changes as follows:
obsArray.subscribe(fn, thisArg, "arrayChange");
The main advantages of subscribing to changes:
Performance is O(1) in most cases, i.e., there’s basically no performance implication at all, because for straightforward operations, (push, splice, etc.) KO supplies the change log without running any diff algorithm. KO now only falls back on the diff algorithm if you’ve made an arbitrary change without using a typical array mutation function.
The change log is filtered down just to give you the items that actually changed.
The observableArray
has array tracking enabled at construction, but
you can extend any other subscribable
(i.e. ko.observable
and ko.computed
) by extending it as follows:
trackable = ko.observable().extend({trackArrayChanges: true});