Browse Source

Refactor keyIsCollectionItem

collection-component
mohamedsalem401 2 years ago
parent
commit
b9ebb756e5
  1. 11
      packages/core/src/data_sources/model/collection_component/CollectionComponent.ts
  2. 1
      packages/core/src/data_sources/model/collection_component/constants.ts
  3. 10
      packages/core/src/dom_components/model/Component.ts
  4. 4
      packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts
  5. 3
      packages/core/src/dom_components/model/types.ts

11
packages/core/src/data_sources/model/collection_component/CollectionComponent.ts

@ -8,7 +8,12 @@ import { ObjectAny } from '../../../common';
import EditorModel from '../../../editor/model/Editor'; import EditorModel from '../../../editor/model/Editor';
import { keyCollectionsStateMap } from '../../../dom_components/model/Component'; import { keyCollectionsStateMap } from '../../../dom_components/model/Component';
import { CollectionComponentDefinition, CollectionDefinition, CollectionState, CollectionsStateMap } from './types'; import { CollectionComponentDefinition, CollectionDefinition, CollectionState, CollectionsStateMap } from './types';
import { keyCollectionDefinition, keyInnerCollectionState, CollectionComponentType } from './constants'; import {
keyCollectionDefinition,
keyInnerCollectionState,
CollectionComponentType,
keyIsCollectionItem,
} from './constants';
import DynamicVariableListenerManager from '../DataVariableListenerManager'; import DynamicVariableListenerManager from '../DataVariableListenerManager';
export default class CollectionComponent extends Component { export default class CollectionComponent extends Component {
@ -148,7 +153,7 @@ function getCollectionItems(
{ {
...block, ...block,
[keyCollectionsStateMap]: collectionsStateMap, [keyCollectionsStateMap]: collectionsStateMap,
isCollectionItem: true, [keyIsCollectionItem]: true,
draggable: false, draggable: false,
deepPropagate: [setCollectionStateMap(collectionsStateMap)], deepPropagate: [setCollectionStateMap(collectionsStateMap)],
}, },
@ -167,7 +172,7 @@ function getCollectionItems(
function setCollectionStateMap(collectionsStateMap: CollectionsStateMap) { function setCollectionStateMap(collectionsStateMap: CollectionsStateMap) {
return (cmp: Component) => { return (cmp: Component) => {
cmp.set('isCollectionItem', true); cmp.set(keyIsCollectionItem, true);
cmp.set(keyCollectionsStateMap, collectionsStateMap); cmp.set(keyCollectionsStateMap, collectionsStateMap);
}; };
} }

1
packages/core/src/data_sources/model/collection_component/constants.ts

@ -1,4 +1,5 @@
export const CollectionComponentType = 'collection-component'; export const CollectionComponentType = 'collection-component';
export const keyCollectionDefinition = 'collectionDefinition'; export const keyCollectionDefinition = 'collectionDefinition';
export const keyInnerCollectionState = 'innerCollectionState'; export const keyInnerCollectionState = 'innerCollectionState';
export const keyIsCollectionItem = '__is_collection_item';
export const CollectionVariableType = 'parent-collection-variable'; export const CollectionVariableType = 'parent-collection-variable';

10
packages/core/src/dom_components/model/Component.ts

@ -55,6 +55,7 @@ import {
} from './SymbolUtils'; } from './SymbolUtils';
import { ComponentDynamicValueWatcher } from './ComponentDynamicValueWatcher'; import { ComponentDynamicValueWatcher } from './ComponentDynamicValueWatcher';
import { DynamicWatchersOptions } from './DynamicValueWatcher'; import { DynamicWatchersOptions } from './DynamicValueWatcher';
import { keyIsCollectionItem } from '../../data_sources/model/collection_component/constants';
export interface IComponent extends ExtractMethods<Component> {} export interface IComponent extends ExtractMethods<Component> {}
export interface SetAttrOptions extends SetOptions, UpdateStyleOptions, DynamicWatchersOptions {} export interface SetAttrOptions extends SetOptions, UpdateStyleOptions, DynamicWatchersOptions {}
@ -73,7 +74,6 @@ export const keySymbolOvrd = '__symbol_ovrd';
export const keyUpdate = ComponentsEvents.update; export const keyUpdate = ComponentsEvents.update;
export const keyUpdateInside = ComponentsEvents.updateInside; export const keyUpdateInside = ComponentsEvents.updateInside;
export const keyCollectionsStateMap = '__collections_state_map'; export const keyCollectionsStateMap = '__collections_state_map';
export const keyIsCollectionItem = '__is_collection_item';
/** /**
* The Component object represents a single node of our template structure, so when you update its properties the changes are * The Component object represents a single node of our template structure, so when you update its properties the changes are
@ -265,7 +265,6 @@ export default class Component extends StyleableModel<ComponentProperties> {
* @ts-ignore */ * @ts-ignore */
collection!: Components; collection!: Components;
componentDVListener: ComponentDynamicValueWatcher; componentDVListener: ComponentDynamicValueWatcher;
initialParent?: Component;
accumulatedPropagatedProps: DeepPropagationArray = []; accumulatedPropagatedProps: DeepPropagationArray = [];
constructor(props: ComponentProperties = {}, opt: ComponentOptions) { constructor(props: ComponentProperties = {}, opt: ComponentOptions) {
@ -356,7 +355,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
return collectionStateMapProp; return collectionStateMapProp;
} }
const parent = this.parent() || this.opt.parent; const parent = this.parent();
return parent?.getCollectionStateMap() || {}; return parent?.getCollectionStateMap() || {};
} }
@ -1144,7 +1143,6 @@ export default class Component extends StyleableModel<ComponentProperties> {
* // -> Component * // -> Component
*/ */
parent(opts: any = {}): Component | undefined { parent(opts: any = {}): Component | undefined {
if (!this.collection && this.initialParent) return this.initialParent;
const coll = this.collection || (opts.prev && this.prevColl); const coll = this.collection || (opts.prev && this.prevColl);
return coll ? coll.parent : undefined; return coll ? coll.parent : undefined;
} }
@ -1632,12 +1630,12 @@ export default class Component extends StyleableModel<ComponentProperties> {
delete obj.open; // used in Layers delete obj.open; // used in Layers
delete obj._undoexc; delete obj._undoexc;
delete obj.delegate; delete obj.delegate;
if (this.get('isCollectionItem')) { if (this.get(keyIsCollectionItem)) {
delete obj[keySymbol]; delete obj[keySymbol];
delete obj[keySymbolOvrd]; delete obj[keySymbolOvrd];
delete obj[keySymbols]; delete obj[keySymbols];
delete obj[keyCollectionsStateMap]; delete obj[keyCollectionsStateMap];
delete obj['isCollectionItem']; delete obj[keyIsCollectionItem];
delete obj.attributes.id; delete obj.attributes.id;
obj['components'] = this.components() obj['components'] = this.components()
.toArray() .toArray()

4
packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts

@ -1,5 +1,5 @@
import { ObjectAny } from '../../common'; import { ObjectAny } from '../../common';
import { CollectionVariableType } from '../../data_sources/model/collection_component/constants'; import { CollectionVariableType, keyIsCollectionItem } from '../../data_sources/model/collection_component/constants';
import { CollectionsStateMap } from '../../data_sources/model/collection_component/types'; import { CollectionsStateMap } from '../../data_sources/model/collection_component/types';
import EditorModel from '../../editor/model/Editor'; import EditorModel from '../../editor/model/Editor';
import Component, { keyCollectionsStateMap } from './Component'; import Component, { keyCollectionsStateMap } from './Component';
@ -69,7 +69,7 @@ export class ComponentDynamicValueWatcher {
} }
private updateSymbolOverride() { private updateSymbolOverride() {
if (!this.component || !this.component.get('isCollectionItem')) return; if (!this.component || !this.component.get(keyIsCollectionItem)) return;
const keys = this.propertyWatcher.getDynamicValuesOfType(CollectionVariableType); const keys = this.propertyWatcher.getDynamicValuesOfType(CollectionVariableType);
const attributesKeys = this.attributeWatcher.getDynamicValuesOfType(CollectionVariableType); const attributesKeys = this.attributeWatcher.getDynamicValuesOfType(CollectionVariableType);

3
packages/core/src/dom_components/model/types.ts

@ -355,7 +355,4 @@ export interface ComponentOptions {
frame?: Frame; frame?: Frame;
temporary?: boolean; temporary?: boolean;
avoidChildren?: boolean; avoidChildren?: boolean;
collectionsStateMap?: CollectionsStateMap;
isCollectionItem?: boolean;
parent?: Component;
} }

Loading…
Cancel
Save