-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Normalize parameters in store/channel #10373
Conversation
Is this bad @shilman?
a415dc3
to
9b91f38
Compare
Because circular deps
@shilman @ndelangen can you take a look? This is mostly done but there are a few things in here that may be controversial:
[1] There is heaps of inconsistent duplication of types in the code base it is a mess. |
lib/api/src/tests/stories.test.js
Outdated
const fullAPI = { on: jest.fn(), setStories: jest.fn(), setOptions: jest.fn() }; | ||
const navigate = jest.fn(); | ||
const store = createMockStore(); | ||
|
||
const { init } = initStories({ store, navigate, provider, fullAPI }); | ||
init(); | ||
|
||
const onSetStoryStoreData = fullAPI.on.mock.calls.find( | ||
([event]) => event === SET_STORY_STORE_DATA | ||
)[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better way to do this for tests @ndelangen?
@@ -401,6 +405,7 @@ export default class StoryStore { | |||
|
|||
return { | |||
...data, | |||
parameters: this.combineStoryParameters(data.parameters, data.kind), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't exactly clear which APIs we should produce denormed/combined parameters for on the story store. Right now it may be very confusing which ones we do it for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree about the need for a separate package to dedupe a small set of core data structures and convenience functions
@tmeasday the I made it that way so we could add more data to it in the future! I think we don't want an extra event, that would probably complicate things more? More async events, race-conditions and stuff? |
# Conflicts: # lib/api/src/modules/stories.ts
I wasn't going to add an extra event, just replace the existing I've discussed this with both you and @shilman and the conclusion we reached is:
Note that 3. is very possible if someone is running a SB6.0 storybook with a ref to a SB7+ iframe. We should put this in place now! Will open a separate issue for this. WDYT @ndelangen? |
I think the v number should be storybook's major version? I like the solution @tmeasday |
I created an issue for the version thing: #10576 let's discuss the numbering there, I will just do |
Some before & after perf numbers from Before: Denormalized
After: Normalized
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few fixes @tmeasday
lib/api/src/index.tsx
Outdated
@@ -350,7 +369,7 @@ export function useSharedState<S>(stateId: string, defaultState?: S) { | |||
[`${SHARED_STATE_SET}-client-${stateId}`]: (s: S) => setState(s), | |||
}; | |||
const stateInitializationHandlers = { | |||
[SET_STORIES]: () => { | |||
[SET_STORY_STORE_DATA]: () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were using SET_STORIES
instead of SET_STORY_STORE_DATA
? Looks like it only got partially reverted?
Thanks for taking those timings @shilman. We could definitely consider not denormalizing/combining parameters on stories in the manager until they are rendered although that could have a bunch of implications that we might not want. We could also memoize the |
@tmeasday we can probably optimize further in a separate PR. before i merge this one, can you look at the chromatic changes? one appears to be related to the timing change and is probably OK (tho weird?!), but the other looks like it's possibly a bug, where |
lib/client-api/src/story_store.ts
Outdated
@@ -333,7 +322,7 @@ export default class StoryStore { | |||
...accumlatedParameters, | |||
argTypes: enhancer({ | |||
...identification, | |||
storyFn, | |||
storyFn: original, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shilman I think the original version of this was looking at the wrong storyFn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the enhancer needs the original story function. Maybe we should be passing that as original
instead of storyFn
??
I think this "fix" actually introduces a bug. Because the enhancer can't look at whether the original story function accepts args.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I misunderstood. You fixed the bug by reverting that part of the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so I just fixed a bug in my own code 👍
Issue: #10361
WIP:
storiesHash
combineParameters
is available.