Last active
August 29, 2015 14:13
-
-
Save szechyjs/5fd1eabc027a4e1c739c to your computer and use it in GitHub Desktop.
kotrackchnagesextender.js
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
/*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