Skip to content

Instantly share code, notes, and snippets.

@michalzubkowicz
Created June 28, 2013 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalzubkowicz/5884766 to your computer and use it in GitHub Desktop.
Save michalzubkowicz/5884766 to your computer and use it in GitHub Desktop.
Knockout Dirty Flag
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