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

7
src/utils/Sorter.js

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

Loading…
Cancel
Save