diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index bcbedb1bc..a12516b93 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -734,21 +734,19 @@ const Component = Backbone.Model.extend(Styleable).extend( }, __getSymbToUp(opts = {}) { + let result = []; const { em } = this; const symbEnabled = em && em.get('symbols'); - const { fromInstance } = opts; - const symbols = this.__getSymbols() || []; - const symbol = this.__getSymbol(); - let result = - symbol && !fromInstance - ? [symbol] - : symbols.filter(md => md.collection || md.prevColl); - if (fromInstance) { - result = result.filter(i => i !== fromInstance); + if (opts.fromInstance || opts.noPropagate || !symbEnabled) { + return result; } - return symbEnabled ? result : []; + const symbols = this.__getSymbols() || []; + const symbol = this.__getSymbol(); + const all = symbol ? [symbol, ...(symbol.__getSymbols() || [])] : symbols; + + return all.filter(s => s !== this); }, __getSymbTop(opts) { @@ -852,6 +850,7 @@ const Component = Backbone.Model.extend(Styleable).extend( toRemove && toRemove.remove({ fromInstance: parent, ...opts }); }; } + !isTemp && this.__logSymbol('remove', toUp, { opts: o, @@ -859,30 +858,6 @@ const Component = Backbone.Model.extend(Styleable).extend( isSymbNested }); toUp.forEach(toUpFn); - - // toUp.forEach(symb => { - // if (isSymbNested) { - // const toRemove = symb.parent().components().at(index); - // toRemove && toRemove.remove(opts); - // // } - - // // // In case of nested symbols, I only need to propagate changes to its instances - // // if (symb.__isSymbolTop() && symb.__getSymbols()) { - // // const toUpInst = symb.__getSymbToUp({ - // // fromInstance: m, - // // ...toUpOpts - // // }); - // // this.__logSymbol('remove-inst', toUpInst, { - // // opts: o, - // // symbol: symb - // // }); - // // toUpInst.forEach(inst => { - // // inst.remove(opts); - // // }); - // } else { - // symb.remove(opts); - // } - // }); } // Remove instance reference from the symbol diff --git a/test/specs/dom_components/model/Symbols.js b/test/specs/dom_components/model/Symbols.js index f36bb6181..c5824b9d8 100644 --- a/test/specs/dom_components/model/Symbols.js +++ b/test/specs/dom_components/model/Symbols.js @@ -423,6 +423,8 @@ describe('Symbols', () => { added.remove(); // All first symbols will remove their copy and only the secComp2 will remain expect(secSymbol.__getSymbols().length).toBe(1); + // First symbols has the previous number of components inside + all.forEach(s => expect(s.components().length).toBe(compInitChild)); }); test('Moving the second instance inside first instances, propagates correctly to all other first symbols', () => {