Browse Source

Adjust removeChildren method

pull/1918/head
Artur Arseniev 8 years ago
parent
commit
b7c063d1b8
  1. 34
      src/dom_components/view/ComponentsView.js
  2. 7
      src/utils/Sorter.js

34
src/dom_components/view/ComponentsView.js

@ -11,19 +11,24 @@ module.exports = Backbone.View.extend({
this.listenTo(coll, 'remove', this.removeChildren); this.listenTo(coll, 'remove', this.removeChildren);
}, },
removeChildren(removed) { removeChildren(removed, coll, opts = {}) {
const em = this.config.em; const em = this.config.em;
const view = removed.view; const view = removed.view;
const temp = removed.opt.temporary; const tempComp = removed.opt.temporary;
const tempRemove = opts.temporary;
if (!view) return; if (!view) return;
view.remove.apply(view); view.remove.apply(view);
const children = view.childrenView; const children = view.childrenView;
children && children.stopListening(); children && children.stopListening();
removed.components().forEach(this.removeChildren.bind(this)); removed.components().forEach(it => this.removeChildren(it, coll, opts));
!temp && removed.removed();
if (em) { if (em && !tempRemove) {
// Remove all related CSS rules // Remove the component from the global list
const id = removed.getId(); const id = removed.getId();
const domc = em.get('DomComponents');
delete domc.componentsById[id];
// Remove all related CSS rules
const allRules = em.get('CssComposer').getAll(); const allRules = em.get('CssComposer').getAll();
allRules.remove( allRules.remove(
allRules.filter( allRules.filter(
@ -31,15 +36,14 @@ module.exports = Backbone.View.extend({
) )
); );
// Remove the component from the global list if (!tempComp) {
const domc = em.get('DomComponents'); const cm = em.get('Commands');
delete domc.componentsById[id]; const hasSign = removed.get('style-signature');
const optStyle = { target: removed };
removed.get('style-signature') && hasSign && cm.run('core:component-style-clear', optStyle);
em removed.removed();
.get('Commands') em.trigger('component:remove', removed);
.run('core:component-style-clear', { target: removed }); }
!temp && em.trigger('component:remove', removed);
} }
}, },

7
src/utils/Sorter.js

@ -320,10 +320,9 @@ module.exports = Backbone.View.extend({
const opts = { const opts = {
avoidStore: 1, avoidStore: 1,
avoidChildren: 1, avoidChildren: 1,
avoidUpdateStyle: 1, avoidUpdateStyle: 1
temporary: 1
}; };
let tempModel = comps.add(dropContent, opts); let tempModel = comps.add(dropContent, { ...opts, temporary: 1 });
dropModel = comps.remove(tempModel, opts); dropModel = comps.remove(tempModel, opts);
this.dropModel = dropModel instanceof Array ? dropModel[0] : dropModel; this.dropModel = dropModel instanceof Array ? dropModel[0] : dropModel;
} }
@ -995,7 +994,7 @@ module.exports = Backbone.View.extend({
modelTemp = targetCollection.add({}, { ...opts }); modelTemp = targetCollection.add({}, { ...opts });
if (model) { if (model) {
modelToDrop = model.collection.remove(model); modelToDrop = model.collection.remove(model, { temporary: 1 });
} }
} else { } else {
modelToDrop = dropContent; modelToDrop = dropContent;

Loading…
Cancel
Save