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;
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);
}
@ -150,24 +151,24 @@ function listDataSourceVariables(dataSource_id: string, em: EditorModel) {
}
function resolveComponent(
symbol: Component,
component: Component,
block: ComponentDefinition,
collectionsStateMap: CollectionsStateMap,
em: EditorModel,
) {
const instance = em.Components.addSymbol(symbol);
const { resolvedCollectionValues: overrideKeys } = resolveBlockValues(collectionsStateMap, block);
Object.keys(overrideKeys).length && instance!.setSymbolOverride(Object.keys(overrideKeys));
instance!.set(overrideKeys);
const { resolvedCollectionValues } = resolveBlockValues(collectionsStateMap, block);
Object.keys(resolvedCollectionValues).length && component!.setSymbolOverride(Object.keys(resolvedCollectionValues));
component!.set(resolvedCollectionValues);
const children: ComponentDefinition[] = [];
for (let index = 0; index < instance!.components().length; index++) {
const childComponent = symbol!.components().at(index);
for (let index = 0; index < component!.components().length; index++) {
const childSymbol = component!.components().at(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 = {
...componentJSON,
components: children,

Loading…
Cancel
Save