From ad4d33b5f845fa99c7991218452007bb291795cd Mon Sep 17 00:00:00 2001 From: Theo Ephraim Date: Wed, 13 May 2015 10:15:17 -0400 Subject: [PATCH 1/3] add options to ignore properties --- backbone.trackit.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backbone.trackit.js b/backbone.trackit.js index 2dc6f4d..b53d8c7 100644 --- a/backbone.trackit.js +++ b/backbone.trackit.js @@ -67,16 +67,19 @@ _trackingChanges: false, _originalAttrs: {}, _unsavedChanges: {}, + _trackitIgnore: {}, // Opt in to tracking attribute changes // between saves. - startTracking: function() { + startTracking: function(options) { + options = options || {}; this._unsavedConfig = _.extend({}, { prompt: 'You have unsaved changes!', unloadRouterPrompt: false, unloadWindowPrompt: false }, this.unsaved || {}); this._trackingChanges = true; + this._trackitIgnore = options.ignore; this._resetTracking(); this._triggerUnsavedChanges(); return this; @@ -88,6 +91,7 @@ this._trackingChanges = false; this._originalAttrs = {}; this._unsavedChanges = {}; + this._trackitIgnore = {}; this._triggerUnsavedChanges(); return this; }, @@ -160,6 +164,8 @@ if (this._trackingChanges && !options.silent && !options.trackit_silent) { _.each(attrs, _.bind(function(val, key) { + // do nothing if ignoring this property + if (_.contains(this._trackitIgnore, key)) return; if (_.isEqual(this._originalAttrs[key], val)) delete this._unsavedChanges[key]; else From aad7a5c30210c2ce360c330da77b327a344608fa Mon Sep 17 00:00:00 2001 From: mehdi-loup Date: Sun, 18 Jun 2017 11:43:12 -0400 Subject: [PATCH 2/3] hotfix/loadash-api-change-contains-to-includes --- backbone.trackit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backbone.trackit.js b/backbone.trackit.js index b53d8c7..ea26932 100644 --- a/backbone.trackit.js +++ b/backbone.trackit.js @@ -165,7 +165,7 @@ if (this._trackingChanges && !options.silent && !options.trackit_silent) { _.each(attrs, _.bind(function(val, key) { // do nothing if ignoring this property - if (_.contains(this._trackitIgnore, key)) return; + if (_.includes(this._trackitIgnore, key)) return; if (_.isEqual(this._originalAttrs[key], val)) delete this._unsavedChanges[key]; else @@ -195,4 +195,4 @@ return oldSync(method, model, options); }); -})(); \ No newline at end of file +})(); From 2676b8466ff3f3054274a4b7a63c81b2be509dfd Mon Sep 17 00:00:00 2001 From: mehdi-loup Date: Sun, 18 Jun 2017 15:01:04 -0400 Subject: [PATCH 3/3] update loadash api --- backbone.trackit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backbone.trackit.js b/backbone.trackit.js index ea26932..6febc75 100644 --- a/backbone.trackit.js +++ b/backbone.trackit.js @@ -10,7 +10,7 @@ // the `unsavedModels` collection, otherwise remove it. var updateUnsavedModels = function(model) { if (!_.isEmpty(model._unsavedChanges)) { - if (!_.findWhere(unsavedModels, {cid:model.cid})) unsavedModels.push(model); + if (!_.find(unsavedModels, {cid:model.cid})) unsavedModels.push(model); } else { unsavedModels = _.filter(unsavedModels, function(m) { return model.cid != m.cid; }); } @@ -24,7 +24,7 @@ // from the `model.unsaved` configuration hash) to evaluate // whether a prompt is needed/returned. var getPrompt = function(fnName) { - var prompt, args = _.rest(arguments); + var prompt, args = _.tail(arguments); // Evaluate and return a boolean result. The given `fn` may be a // boolean value, a function, or the name of a function on the model. var evaluateModelFn = function(model, fn) {