You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Areson edited this page Apr 25, 2012
·
2 revisions
Provides "transactional" methods for observables, allowing them to prevent updates to subscribers until a commit is done. All changes made to an observable that are uncommitted will not be reflected by subscribers and will not be available via reads of the observable.
varobservable=ko.observable("foo").extend({protected: true});//This change does not take effect...observable(42);//...so the value we ready is still "foo"varvalue=observable();observable.commit();//Now we read "42"value=observable();
The standard protection extension provides transactional support for only basic observables and observable arrays. Any observables contained inside the protected observable will not be protected by default. You can force them to be protected by turning on "deep" protection.
varobservable=ko.observable({foo: ko.observable("foo"),bar: ko.observable("bar")}).extend({protected: {deep: true}});//These changes won't take effect...observable().foo(42);//...until they are committedobservable.commit();
Finally, any uncommitted changes can be rolled back by calling the reset method.