Skip to content

Adds a single isDirty flag to the viewmodel, that by default subscribes to all non-computed obeservables.

Notifications You must be signed in to change notification settings

larsholm/knockout.dirtytracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

knockout dirty tracker

Automatic isDirty flag/tracking for KnockoutJS viewmodels

Adds a single isDirty flag to the viewmodel, that by default subscribes to all non-computed observables automatically.

When dirtyTracker.track is called on a viewmodel an observable is added:

vm.isDirty()

The flag is set to true if any observable property of the viewmodel is changed.
If an observable in the viewmodel should not be tracked, use
ko.observable().extend({ dirtyTracked: false });

If a computed observable in the viewmodel should be tracked, use
ko.observable().extend({ dirtyTracked: true });

The dirty flag itself is not tracked, so it can be manually be set:
vm.isDirty(false);

To enable tracking simply call:
dirtyTracker.track(vm)
before
ko.applyBindings(vm);
to enable tracking.

Demo on JSFiddle.net:
http://jsfiddle.net/larsholm/y3t7ku5e/4/

About

Adds a single isDirty flag to the viewmodel, that by default subscribes to all non-computed obeservables.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published