Skip to content

Commit

Permalink
Fix undefined props after calling setRoot with the same componentId (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yogevbd committed May 15, 2023
1 parent dcff945 commit 73ee650
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 2 additions & 6 deletions lib/src/commands/LayoutTreeCrawler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('LayoutTreeCrawler', () => {

it('pass props to option processor', () => {
const passProps = { someProp: 'here' };
when(mockedStore.getPropsForId('testId')).thenReturn(passProps);
when(mockedStore.getPendingProps('testId')).thenReturn(passProps);
const node = {
id: 'testId',
type: LayoutType.Component,
Expand All @@ -67,11 +67,7 @@ describe('LayoutTreeCrawler', () => {
};
uut.crawl(node, CommandName.SetRoot);
verify(
mockedOptionsProcessor.processOptions(
CommandName.SetRoot,
undefined,
deepEqual(passProps)
)
mockedOptionsProcessor.processOptions(CommandName.SetRoot, undefined, deepEqual(passProps))
).called();
});
});
2 changes: 1 addition & 1 deletion lib/src/commands/LayoutTreeCrawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class LayoutTreeCrawler {
if (node.type === LayoutType.Component) {
this.handleComponent(node);
}
const componentProps = this.store.getPropsForId(node.id) || undefined;
const componentProps = this.store.getPendingProps(node.id) || undefined;
this.optionsProcessor.processOptions(commandName, node.data.options, componentProps);
node.children.forEach((value: LayoutNode) => this.crawl(value, commandName));
}
Expand Down
4 changes: 4 additions & 0 deletions lib/src/components/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class Store {
this.pendingPropsById[componentId] = newProps;
}

getPendingProps(componentId: string) {
return this.pendingPropsById[componentId];
}

getPropsForId(componentId: string) {
if (this.pendingPropsById[componentId]) {
this.propsById[componentId] = this.pendingPropsById[componentId];
Expand Down

0 comments on commit 73ee650

Please sign in to comment.