Browse Source

Use key var for symbols

symbols-2
Artur Arseniev 6 years ago
parent
commit
1f409871e8
  1. 20
      src/dom_components/model/Component.js

20
src/dom_components/model/Component.js

@ -27,6 +27,8 @@ const escapeRegExp = str => {
const avoidInline = em => em && em.getConfig('avoidInlineStyle'); const avoidInline = em => em && em.getConfig('avoidInlineStyle');
export const eventDrag = 'component:drag'; export const eventDrag = 'component:drag';
export const keySymbol = '__symbol';
export const keySymbolOf = '__symbol';
export const keySymbol2w = '__symbol2w'; export const keySymbol2w = '__symbol2w';
/** /**
@ -591,7 +593,7 @@ const Component = Backbone.Model.extend(Styleable).extend(
}, },
__isSymbol() { __isSymbol() {
return isArray(this.get('__symbol')); return isArray(this.get(keySymbol));
}, },
__isSymbolTop() { __isSymbolTop() {
@ -600,11 +602,11 @@ const Component = Backbone.Model.extend(Styleable).extend(
}, },
__getSymbolOf() { __getSymbolOf() {
return this.get('__symbolOf'); return this.get(keySymbolOf);
}, },
__getSymbToUp(opts = {}) { __getSymbToUp(opts = {}) {
const symbol = this.get('__symbol'); const symbol = this.get(keySymbol);
const symbolOf = this.__getSymbolOf(); const symbolOf = this.__getSymbolOf();
let result = !this.__isSymbol() let result = !this.__isSymbol()
? [] ? []
@ -641,8 +643,8 @@ const Component = Backbone.Model.extend(Styleable).extend(
const attrs = changed.attributes || {}; const attrs = changed.attributes || {};
delete changed.status; delete changed.status;
delete changed.open; delete changed.open;
delete changed.__symbol; delete changed[keySymbol];
delete changed.__symbolOf; delete changed[keySymbolOf];
delete changed.attributes; delete changed.attributes;
delete attrs.id; delete attrs.id;
if (!isEmptyObj(attrs)) changed.attributes = attrs; if (!isEmptyObj(attrs)) changed.attributes = attrs;
@ -1106,13 +1108,13 @@ const Component = Backbone.Model.extend(Styleable).extend(
// Symbols // Symbols
// If I clone an inner symbol, I have to reset it // If I clone an inner symbol, I have to reset it
cloned.unset('__symbol'); cloned.unset(keySymbol);
if (opt.symbol) { if (opt.symbol) {
const symbols = this.get('__symbol') || []; const symbols = this.get(keySymbol) || [];
symbols.push(cloned); symbols.push(cloned);
this.set('__symbol', symbols); this.set(keySymbol, symbols);
this.__initSymb(); this.__initSymb();
cloned.set('__symbolOf', this); cloned.set(keySymbolOf, this);
opt.symbol2w && cloned.set(keySymbol2w, 1); opt.symbol2w && cloned.set(keySymbol2w, 1);
} }

Loading…
Cancel
Save