Skip to content

Commit

Permalink
Configurable rate limit dirty check for performance reasons #201
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Jul 14, 2023
1 parent 4b31b7f commit 844b6cd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions grails-app/assets/javascripts/knockout-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
* @param isInitiallyDirty
* @returns an object (function) with the methods 'isDirty' and 'reset'
*/
ko.dirtyFlag = function (root, isInitiallyDirty) {
ko.dirtyFlag = function (root, isInitiallyDirty, rateLimit) {
var result = function () {
};
var _isInitiallyDirty = ko.observable(isInitiallyDirty || false);
Expand All @@ -93,11 +93,12 @@
var _initialState = ko.observable(getRepresentation());

result.isDirty = ko.pureComputed(function () {
console.log("isDirty called");
var dirty = _isInitiallyDirty() || _initialState() !== getRepresentation();

return dirty;
}).extend({rateLimit: 500});
});
if (rateLimit) {
result.isDirty = result.isDirty.extend({rateLimit: 500});
}

result.reset = function () {
_initialState(getRepresentation());
Expand Down

0 comments on commit 844b6cd

Please sign in to comment.