Skip to content

Commit

Permalink
Temporarily adding components via the Sorter no longer triggers add/c…
Browse files Browse the repository at this point in the history
…hange 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.
  • Loading branch information
thecodefish committed Aug 3, 2017
1 parent 5819133 commit 6e1952b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/editor/model/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -281,7 +287,7 @@ module.exports = Backbone.Model.extend({
this.listenTo(model, evn, this.componentsUpdated);

if(!avSt)
this.componentsUpdated();
this.componentsUpdated(model, val, opt);
},

/**
Expand Down Expand Up @@ -310,7 +316,7 @@ module.exports = Backbone.Model.extend({
var avSt = opt ? opt.avoidStore : 0;

if(!avSt)
this.componentsUpdated();
this.componentsUpdated(model, val, opt);
},

/**
Expand Down
4 changes: 2 additions & 2 deletions src/utils/Sorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6e1952b

Please sign in to comment.