Skip to content

Instantly share code, notes, and snippets.

@szechyjs
Last active August 29, 2015 14:13
Show Gist options
  • Save szechyjs/5fd1eabc027a4e1c739c to your computer and use it in GitHub Desktop.
Save szechyjs/5fd1eabc027a4e1c739c to your computer and use it in GitHub Desktop.
kotrackchnagesextender.js
/*global ko*/
ko.extenders.trackChange = function (target, track) {
"use strict";
if (track) {
target.isDirty = ko.observable(false);
target.originalValue = target();
target.subscribe(function (newValue) {
// use != not !== so numbers will equate naturally
target.isDirty(newValue !== target.originalValue);
});
}
return target;
};
ko.observable.fn.resetDirty = function() {
if (this.isDirty) {
this.isDirty(false);
this.originalValue = this();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment