Browse Source

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.
pull/202/head
thecodefish 9 years ago
parent
commit
6e1952b62b
  1. 10
      src/editor/model/Editor.js
  2. 4
      src/utils/Sorter.js

10
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);
},
/**

4
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;

Loading…
Cancel
Save