From 6e1952b62b23d66818cd530dbceae309dbdf9d62 Mon Sep 17 00:00:00 2001 From: thecodefish Date: Thu, 3 Aug 2017 14:58:59 +1200 Subject: [PATCH] Temporarily adding components via the Sorter no longer triggers add/change events Utils/Sorter will temporarily add a component to the collection in order to capture its properties, then remove it immediately. This triggers the component:add, component:remove, and change:changesCount events (and possibly others). The temporary addition/removal now includes an option flag 'temporary' which can be used in event handlers to detect this scenario. In addition, the editor.componentsUpdated handler performs the same check which prevents updating the changesCount as well as updating storage. --- src/editor/model/Editor.js | 10 ++++++++-- src/utils/Sorter.js | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index a6f9f80b1..431076262 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -161,6 +161,12 @@ module.exports = Backbone.Model.extend({ * @private * */ componentsUpdated(model, val, opt) { + var temp = opt ? opt.temporary : 0; + if (temp) { + //component has been added temporarily - do not update storage or record changes + return; + } + timedInterval && clearInterval(timedInterval); timedInterval = setTimeout(() => { var count = this.get('changesCount') + 1; @@ -281,7 +287,7 @@ module.exports = Backbone.Model.extend({ this.listenTo(model, evn, this.componentsUpdated); if(!avSt) - this.componentsUpdated(); + this.componentsUpdated(model, val, opt); }, /** @@ -310,7 +316,7 @@ module.exports = Backbone.Model.extend({ var avSt = opt ? opt.avoidStore : 0; if(!avSt) - this.componentsUpdated(); + this.componentsUpdated(model, val, opt); }, /** diff --git a/src/utils/Sorter.js b/src/utils/Sorter.js index ae4f762a2..494518436 100644 --- a/src/utils/Sorter.js +++ b/src/utils/Sorter.js @@ -283,8 +283,8 @@ module.exports = Backbone.View.extend({ if (dropContent && em) { if (!dropModel) { let comps = em.get('DomComponents').getComponents(); - let tempModel = comps.add(dropContent, {avoidUpdateStyle: 1}); - dropModel = comps.remove(tempModel); + let tempModel = comps.add(dropContent, {avoidUpdateStyle: 1, temporary: 1}); + dropModel = comps.remove(tempModel, {temporary: 1}); this.dropModel = dropModel instanceof Array ? dropModel[0] : dropModel; } return dropModel;