Browse Source

Refactor keyIsCollectionItem

pull/6359/head
mohamedsalem401 1 year 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 { keyCollectionsStateMap } from '../../../dom_components/model/Component';
import { CollectionComponentDefinition, CollectionDefinition, CollectionState, CollectionsStateMap } from './types';
import { keyCollectionDefinition, keyInnerCollectionState, CollectionComponentType } from './constants';
import {
keyCollectionDefinition,
keyInnerCollectionState,
CollectionComponentType,
keyIsCollectionItem,
} from './constants';
import DynamicVariableListenerManager from '../DataVariableListenerManager';
export default class CollectionComponent extends Component {
@ -148,7 +153,7 @@ function getCollectionItems(
{
...block,
[keyCollectionsStateMap]: collectionsStateMap,
isCollectionItem: true,
[keyIsCollectionItem]: true,
draggable: false,
deepPropagate: [setCollectionStateMap(collectionsStateMap)],
},
@ -167,7 +172,7 @@ function getCollectionItems(
function setCollectionStateMap(collectionsStateMap: CollectionsStateMap) {
return (cmp: Component) => {
cmp.set('isCollectionItem', true);
cmp.set(keyIsCollectionItem, true);
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 keyCollectionDefinition = 'collectionDefinition';
export const keyInnerCollectionState = 'innerCollectionState';
export const keyIsCollectionItem = '__is_collection_item';
export const CollectionVariableType = 'parent-collection-variable';

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

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

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

@ -1,5 +1,5 @@
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 EditorModel from '../../editor/model/Editor';
import Component, { keyCollectionsStateMap } from './Component';
@ -69,7 +69,7 @@ export class ComponentDynamicValueWatcher {
}
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 attributesKeys = this.attributeWatcher.getDynamicValuesOfType(CollectionVariableType);

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

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

Loading…
Cancel
Save