Skip to content

Commit

Permalink
Update globals/args persistence handling as per gert
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Aug 6, 2021
1 parent 779b996 commit 3b69025
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/client-api/src/new/ArgsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ export class ArgsStore {
}

updateFromPersisted(story: Story<any>, persisted: Args) {
// NOTE: we use `combineArgs` here rather than `combineParameters` because changes to arg
// array values are persisted in the URL as sparse arrays, and we have to take that into
// account when overriding the initialArgs (e.g. we patch [,'changed'] over ['initial', 'val'])
this.argsByStoryId[story.id] = combineArgs(
this.argsByStoryId[story.id],
// Use the argType to ensure we aren't persisting the wrong type of value to the type.
// For instance you could try and set a string-valued arg to a number by changing the URL
mapArgsToTypes(persisted, story.argTypes)
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/client-api/src/new/GlobalsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class GlobalsStore {
if (this.allowedGlobalNames.has(key)) acc[key] = value;
return acc;
}, {} as Globals);
// TODO(Gert) -- why do we use combineParameters here?
// Note that unlike args, we do not have the same type information for globals to allow us
// to type check them here, so we just set them naively
this.globals = combineParameters(this.globals, allowedUrlGlobals);
}

Expand Down

0 comments on commit 3b69025

Please sign in to comment.