Browse Source

Only use 1 symbol to be used for each item in the collections

collection-component
mohamedsalem401 2 years ago
parent
commit
c6f4ad4e3a
  1. 21
      packages/core/src/data_sources/model/collection_component/CollectionComponent.ts

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

@ -94,7 +94,8 @@ export default class CollectionComponent extends Component {
const model = type.model; const model = type.model;
blockComponent = new model(clonedBlock, opt); blockComponent = new model(clonedBlock, opt);
} }
const cmpDefinition = resolveComponent(blockComponent!, block, collectionsStateMap, em); const instance = em.Components.addSymbol(blockComponent!);
const cmpDefinition = resolveComponent(instance!, block, collectionsStateMap, em);
components.push(cmpDefinition); components.push(cmpDefinition);
} }
@ -150,24 +151,24 @@ function listDataSourceVariables(dataSource_id: string, em: EditorModel) {
} }
function resolveComponent( function resolveComponent(
symbol: Component, component: Component,
block: ComponentDefinition, block: ComponentDefinition,
collectionsStateMap: CollectionsStateMap, collectionsStateMap: CollectionsStateMap,
em: EditorModel, em: EditorModel,
) { ) {
const instance = em.Components.addSymbol(symbol); const { resolvedCollectionValues } = resolveBlockValues(collectionsStateMap, block);
const { resolvedCollectionValues: overrideKeys } = resolveBlockValues(collectionsStateMap, block); Object.keys(resolvedCollectionValues).length && component!.setSymbolOverride(Object.keys(resolvedCollectionValues));
Object.keys(overrideKeys).length && instance!.setSymbolOverride(Object.keys(overrideKeys)); component!.set(resolvedCollectionValues);
instance!.set(overrideKeys);
const children: ComponentDefinition[] = []; const children: ComponentDefinition[] = [];
for (let index = 0; index < instance!.components().length; index++) { for (let index = 0; index < component!.components().length; index++) {
const childComponent = symbol!.components().at(index); const childSymbol = component!.components().at(index);
const childBlock = block['components']![index]; const childBlock = block['components']![index];
children.push(resolveComponent(childComponent, childBlock, collectionsStateMap, em)); const childJSON = resolveComponent(childSymbol, childBlock, collectionsStateMap, em);
children.push(childJSON);
} }
const componentJSON = instance!.toJSON(); const componentJSON = component!.toJSON();
const componentDefinition: ComponentDefinition = { const componentDefinition: ComponentDefinition = {
...componentJSON, ...componentJSON,
components: children, components: children,

Loading…
Cancel
Save