Created
June 28, 2013 13:44
-
-
Save michalzubkowicz/5884766 to your computer and use it in GitHub Desktop.
Knockout Dirty Flag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.dirtyFlag = ko.dirtyFlag(this); | |
ko.dirtyFlag = function(root) { | |
var _isDirty = ko.observable(false); | |
var result = ko.computed(function() { | |
if (!_isDirty()) { | |
ko.toJS(root); //just for subscriptions | |
} | |
return _isDirty(); | |
}); | |
result.subscribe(function() { | |
if (!_isDirty()) { | |
_isDirty(true); | |
} | |
}); | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment