From a5146eb2cf08a080cb0280092973928750bb79d6 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 10 Jun 2024 18:24:07 +0400 Subject: [PATCH] Up symbols method names --- src/dom_components/index.ts | 11 +++++----- src/dom_components/model/Component.ts | 14 ++++++------- src/dom_components/model/SymbolUtils.ts | 28 ++++++++++++------------- src/dom_components/types.ts | 11 ++++++++++ 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/dom_components/index.ts b/src/dom_components/index.ts index 137ab34b1..cf2dd5801 100644 --- a/src/dom_components/index.ts +++ b/src/dom_components/index.ts @@ -102,7 +102,8 @@ import ComponentView, { IComponentView } from './view/ComponentView'; import ComponentWrapperView from './view/ComponentWrapperView'; import ComponentsView from './view/ComponentsView'; import ComponentHead, { type as typeHead } from './model/ComponentHead'; -import { getSymbol, getSymbols, getSymbolsToUpdate, isSymbolMain } from './model/SymbolUtils'; +import { getSymbolMain, getSymbolInstances, getSymbolsToUpdate, isSymbolMain } from './model/SymbolUtils'; +import { SymbolInfo } from './types'; export type ComponentEvent = | 'component:create' @@ -704,7 +705,7 @@ export default class ComponentManager extends ItemManagerModule} */ getSymbols() { @@ -716,11 +717,11 @@ export default class ComponentManager extends ItemManagerModule { if ( // Symbols should always have an id - getSymbol(this) || - getSymbols(this) || + getSymbolMain(this) || + getSymbolInstances(this) || // Components with script should always have an id this.get('script-export') || this.get('script') @@ -1258,15 +1258,15 @@ export default class Component extends StyleableModel { // Symbols // If I clone an inner symbol, I have to reset it cloned.set(keySymbols, 0); - const symbol = getSymbol(this); - const symbols = getSymbols(this); + const symbol = getSymbolMain(this); + const symbols = getSymbolInstances(this); if (!opt.symbol && (symbol || symbols)) { cloned.set(keySymbol, 0); cloned.set(keySymbols, 0); } else if (symbol) { // Contains already a reference to a symbol - symbol.set(keySymbols, [...getSymbols(symbol)!, cloned]); + symbol.set(keySymbols, [...getSymbolInstances(symbol)!, cloned]); initSymbol(cloned); } else if (opt.symbol) { // Request to create a symbol diff --git a/src/dom_components/model/SymbolUtils.ts b/src/dom_components/model/SymbolUtils.ts index 4063410f3..bdaf833f7 100644 --- a/src/dom_components/model/SymbolUtils.ts +++ b/src/dom_components/model/SymbolUtils.ts @@ -17,9 +17,9 @@ export const isSymbolTop = (symbol: Component) => { export const isSymbolNested = (symbol: Component) => { if (!isSymbol(symbol)) return false; - const symbTopSelf = getSymbolTop(isSymbolMain(symbol) ? symbol : getSymbol(symbol)!); + const symbTopSelf = getSymbolTop(isSymbolMain(symbol) ? symbol : getSymbolMain(symbol)!); const symbTop = getSymbolTop(symbol); - const symbTopMain = isSymbolMain(symbTop) ? symbTop : getSymbol(symbTop); + const symbTopMain = isSymbolMain(symbTop) ? symbTop : getSymbolMain(symbTop); return symbTopMain !== symbTopSelf; }; @@ -29,7 +29,7 @@ export const initSymbol = (symbol: Component) => { symbol.__symbReady = true; }; -export const getSymbol = (symbol: Component): Component | undefined => { +export const getSymbolMain = (symbol: Component): Component | undefined => { let result = symbol.get(keySymbol); if (result && isString(result)) { @@ -45,7 +45,7 @@ export const getSymbol = (symbol: Component): Component | undefined => { return result || undefined; }; -export const getSymbols = (symbol?: Component): Component[] | undefined => { +export const getSymbolInstances = (symbol?: Component): Component[] | undefined => { let symbs = symbol?.get(keySymbols); if (symbs && isArray(symbs)) { @@ -81,9 +81,9 @@ export const getSymbolsToUpdate = (symb: Component, opts: SymbolToUpOptions = {} return result; } - const symbols = getSymbols(symb) || []; - const symbol = getSymbol(symb); - const all = symbol ? [symbol, ...(getSymbols(symbol) || [])] : symbols; + const symbols = getSymbolInstances(symb) || []; + const symbol = getSymbolMain(symb); + const all = symbol ? [symbol, ...(getSymbolInstances(symbol) || [])] : symbols; result = all .filter(s => s !== symb) // Avoid updating those with override @@ -106,8 +106,8 @@ export const getSymbolTop = (symbol: Component, opts?: any) => { }; export const logSymbol = (symb: Component, type: string, toUp: Component[], opts: any = {}) => { - const symbol = getSymbol(symb); - const symbols = getSymbols(symb); + const symbol = getSymbolMain(symb); + const symbols = getSymbolInstances(symb); if (!symbol && !symbols) { return; @@ -183,14 +183,14 @@ export const updateSymbolComps = (symbol: Component, m: Component, c: Components // Add } else if (o.add) { let addedInstances: Component[] = []; - const isMainSymb = !!getSymbols(symbol); + const isMainSymb = !!getSymbolInstances(symbol); const toUp = getSymbolsToUpdate(symbol, { ...toUpOpts, changed: 'components:add', }); if (toUp.length) { - const addSymb = getSymbol(m); - addedInstances = (addSymb ? getSymbols(addSymb) : getSymbols(m)) || []; + const addSymb = getSymbolMain(m); + addedInstances = (addSymb ? getSymbolInstances(addSymb) : getSymbolInstances(m)) || []; addedInstances = [...addedInstances]; addedInstances.push(addSymb ? addSymb : m); } @@ -214,12 +214,12 @@ export const updateSymbolComps = (symbol: Component, m: Component, c: Components // Remove } else { // Remove instance reference from the symbol - const symb = getSymbol(m); + const symb = getSymbolMain(m); symb && !o.temporary && symb.set( keySymbols, - getSymbols(symb)!.filter(i => i !== m) + getSymbolInstances(symb)!.filter(i => i !== m) ); // Propagate remove only if the component is an inner symbol diff --git a/src/dom_components/types.ts b/src/dom_components/types.ts index e8f3c0819..ef69efcd6 100644 --- a/src/dom_components/types.ts +++ b/src/dom_components/types.ts @@ -1,9 +1,20 @@ +import Component from './model/Component'; + export enum ActionLabelComponents { remove = 'component:remove', add = 'component:add', move = 'component:move', } +export interface SymbolInfo { + isSymbol: boolean; + isMain: boolean; + isInstance: boolean; + main?: Component; + instances: Component[]; + relatives: Component[]; +} + export enum ComponentsEvents { /** * @event `component:add` New component added.