Skip to content

Commit

Permalink
reset all args to its initial value when onResetArgs is triggerd with…
Browse files Browse the repository at this point in the history
…out argNames
  • Loading branch information
Tomastomaslol committed May 15, 2022
1 parent 385b7d7 commit b318c25
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/preview-web/src/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class Preview<TFramework extends AnyFramework> {
const render = this.storyRenders.find((r) => r.id === storyId);
const story = render?.story || (await this.storyStore.loadStory({ storyId }));

const argNamesToReset = argNames || Object.keys(this.storyStore.args.get(storyId));
const argNamesToReset = argNames || Object.keys(story.initialArgs);
const updatedArgs = argNamesToReset.reduce((acc, argName) => {
acc[argName] = story.initialArgs[argName];
return acc;
Expand Down
4 changes: 2 additions & 2 deletions lib/preview-web/src/PreviewWeb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ describe('PreviewWeb', () => {
forceRemount: false,
storyContext: expect.objectContaining({
initialArgs: { foo: 'a' },
args: { foo: 'a' },
args: { foo: 'a', new: 'value' },
}),
}),
undefined // this is coming from view.prepareForStory, not super important
Expand All @@ -1133,7 +1133,7 @@ describe('PreviewWeb', () => {
await waitForEvents([Events.STORY_ARGS_UPDATED]);
expect(mockChannel.emit).toHaveBeenCalledWith(Events.STORY_ARGS_UPDATED, {
storyId: 'component-one--a',
args: { foo: 'a' },
args: { foo: 'a', new: 'value' },
});
});
});
Expand Down

0 comments on commit b318c25

Please sign in to comment.