Browse Source

Clean Component from old logs/comments

symbols-2
Artur Arseniev 6 years ago
parent
commit
a6676bbbc4
  1. 103
      src/dom_components/model/Component.js
  2. 11
      test/specs/dom_components/model/Symbols.js

103
src/dom_components/model/Component.js

@ -587,14 +587,21 @@ const Component = Backbone.Model.extend(Styleable).extend(
}, },
__logSymbol(type, toUp, opts = {}) { __logSymbol(type, toUp, opts = {}) {
// const symbols = this.__getSymbols(); const symbol = this.__getSymbol();
// console.log(`symbols:${type}`, const symbols = this.__getSymbols();
// this.cid, if (!symbol && !symbols) return;
// 'hasSymbol', this.__getSymbol() ? 'Y' : 'N', console.log(
// 'hasSymbols', symbols ? symbols.length : 'N', `symbols:${type}`,
// 'toUp', toUp.map(i => i.cid), this.cid,
// 'opts', opts 'hasSymbol',
// ); symbol ? 'Y' : 'N',
'hasSymbols',
symbols ? symbols.length : 'N',
'toUp',
toUp.map(i => i.cid),
'opts',
opts
);
}, },
__initSymb() { __initSymb() {
@ -689,85 +696,37 @@ const Component = Backbone.Model.extend(Styleable).extend(
const toUpOpts = { fromInstance }; const toUpOpts = { fromInstance };
if (!o) { if (!o) {
// Reset const toUp = this.__getSymbToUp(toUpOpts);
// !this.opt.temporary && this.__logSymbol('reset', toUp);
// console.log( toUp.forEach(symb => {
// 'Reset cid',
// this.cid,
// o,
// 'isSymb',
// this.__isSymbol(),
// 'symbToUp',
// this.__getSymbToUp(toUpOpts),
// { toUpOpts }
// );
this.__getSymbToUp(toUpOpts).forEach(symb => {
const newMods = m.models.map(mod => mod.clone({ symbol: 1 })); const newMods = m.models.map(mod => mod.clone({ symbol: 1 }));
symb.components().reset(newMods, { fromInstance: this, ...c }); symb.components().reset(newMods, { fromInstance: this, ...c });
}); });
} else if (o.add) { } else if (o.add) {
// Add // Add
const addedInstances = m.__getSymbToUp(toUpOpts); const addedInstances = m.__getSymbToUp(toUpOpts);
// !m.opt.temporary && const toUp = this.__getSymbToUp(toUpOpts);
// console.log( !m.opt.temporary &&
// `Added cid ${m.cid} (symb: ${m.__isSymbol()}) in ${ this.__logSymbol('add', toUp, { opts: o, addedInstances, added: m });
// this.cid // Here, before appending new symbol, I have to ensure there are no previosly
// } (symb: ${this.__isSymbol()})`, // created symbols (eg. used mainly when drag components around)
// 'SymbToUp added', toUp.forEach(symb => {
// addedInstances,
// 'symbToUp',
// this.__getSymbToUp(toUpOpts),
// { toUpOpts }
// );
// Here, before appending new symbol, I have to ensure there no already previosly
// created symbol (eg. used mainly when drag components around)
this.__getSymbToUp(toUpOpts).forEach(symb => {
const symbTop = symb.__getSymbTop(); const symbTop = symb.__getSymbTop();
const symbPrev = addedInstances.filter(addedInst => { const symbPrev = addedInstances.filter(addedInst => {
const addedTop = addedInst.__getSymbTop({ prev: 1 }); const addedTop = addedInst.__getSymbTop({ prev: 1 });
return symbTop && addedTop && addedTop === symbTop; return symbTop && addedTop && addedTop === symbTop;
})[0]; })[0];
const toAppend = symbPrev || m.clone({ symbol: 1 }); const toAppend = symbPrev || m.clone({ symbol: 1 });
// If this is the instance which triggered the main update
// I have to realign it as other instances
// if (fromInstance === symb) {
// const appended = o.toAppend;
// const symbMain = appended.get('__symbol')[0];
// appended.set('__symbolOf', symbMain);
// appended.unset('__symbol');
// symbMain.unset('__symbolOf');
// symbMain.get('__symbol').push(appended);
// !m.opt.temporary && console.log('Exit, fromInstance === symb', fromInstance, 'toAppend', appended, symbMain.get('__symbol'))
// return;
// }
// !m.opt.temporary &&
// console.log(
// 'Added inner',
// toAppend.cid,
// 'of',
// symb.cid,
// `(symb ${symb.__isSymbol()})`,
// { symb, symbPrev, toAppend }
// );
symb.append(toAppend, { fromInstance: this, toAppend: m, ...o }); symb.append(toAppend, { fromInstance: this, toAppend: m, ...o });
}); });
} else { } else {
// Remove if (!m.__isSymbolTop()) {
// !m.opt.temporary && // Allow removing single instances
// console.log( const toUp = m.__getSymbToUp(toUpOpts);
// 'Remove cid', !m.opt.temporary &&
// m.cid, this.__logSymbol('remove', toUp, { opts: o, removed: m.cid });
// m.toHTML(), toUp.forEach(symb => symb.remove({ fromInstance: m, ...o }));
// o, }
// 'isSymb',
// m.__isSymbol(),
// 'symbToUp',
// m.__getSymbToUp(toUpOpts),
// { toUpOpts }
// );
const symbToUp = m.__getSymbToUp(toUpOpts);
!m.__isSymbolTop() &&
symbToUp.forEach(symb => symb.remove({ fromInstance: m, ...o }));
} }
}, },

11
test/specs/dom_components/model/Symbols.js

@ -156,7 +156,7 @@ describe('Symbols', () => {
); );
}); });
test('Moving a new added component, will propagate the action in all symbols', () => { test('Moving a new added component in the instance, will propagate the action in all symbols', () => {
const added = comp.append(simpleComp)[0]; const added = comp.append(simpleComp)[0];
const newChildLen = compInitChild + 1; const newChildLen = compInitChild + 1;
added.move(comp, { at: 0 }); added.move(comp, { at: 0 });
@ -181,6 +181,15 @@ describe('Symbols', () => {
).toBe(allInst.length); ).toBe(allInst.length);
}); });
test.skip('Moving a new added component in the symbol, will propagate the action in all instances', () => {
const added = symbol.append(simpleComp)[0];
const newChildLen = compInitChild + 1;
added.move(symbol, { at: 0 });
const symbRef = added.__getSymbol();
// All symbols still have the same amount of components
all.forEach(cmp => expect(cmp.components().length).toBe(newChildLen));
});
test('Adding a class, reflects changes to all symbols', () => { test('Adding a class, reflects changes to all symbols', () => {
const initSel = symbol.getSelectorsString(); const initSel = symbol.getSelectorsString();
all.forEach(cmp => expect(cmp.getSelectorsString()).toBe(initSel)); all.forEach(cmp => expect(cmp.getSelectorsString()).toBe(initSel));

Loading…
Cancel
Save