-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Overhaul start.js and event emitting/listening #9914
Conversation
For what it's worth I found the duplication of selectedKind & selectedStory suer confusing as I was learning my way around the code base. If we could nuke them it would be a great win for clarity. Breaking changes in 6.0 or bust..... |
OK, refactor is complete and at first blush appears to be working. I still want to add some tests (and I probably broke the existing ones). Will update the top comment when I am done and call for review but @shilman @ndelangen -- do you have thoughts on the |
I think it's fine to remove it if we provide migration instructions: const { id, store } = context;
const { kind: selectedKind, name: selectedStory } = store.fromId(id); |
@shilman it's not even that complicated, |
Whoops I hadn't even pushed what I was referring to above 馃槉 |
1c0db7f
to
a35c3a6
Compare
cc @kroeder -- perhaps we need to make the type here "not quite a node module" -- I suppose the issue here is that the require-context hook we use doesn't implement `req.resolve()`: https://www.npmjs.com/package/@storybook/addon-storyshots#configure-jest-to-work-with-webpacks-requirecontext We should probably just fix it so it does, but for now.
|
||
- `selectedKind`/`selectedStory` -- replaced by `kind`/`name` | ||
- `configApi` | ||
- `storyStore` |
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.
don't we need access to the store?
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 added back the store just to docs context.
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.
Great work! Lots of changes, but if there are no objections, I think we should merge and address issues in follow up PRs
A refactor of the
start.js
/@storybook/client-api
code base.What I've done:
@storybook/core/src/client/preview
directory started by @kroeder in WIP: [ts-migration] lib/core聽#9870start.ts
intoStoryRenderer.tsx
& wrote testsstart.ts
intomakeConfigure.ts
& wrote testsPreviously things were a bit of a mess for a few reasons:
Preview module system
This PR doesn't attempt to "fully" solve all of this and design a new module system from scratch (see notes below). Instead I just tried to rationalize things in the lowest impact way possible. Here's what I did:
A) Each module only has access to the channel and the store. They can calls APIs on the store if they wish.
B) Each module is responsible for listening to the events that drive their own behaviour from the manager or elsewhere in the preview (e.g. the rendering code listens to the
RENDER_CURRENT_STORY
event which is emitted by the store).C) All modules should emit events (either "imperative" -- ie talking to another module, or "past tense" -- ie something just happened) on the channel.
Events on startup
To avoid a delay in emitting the
SET_STORIES
event, we simply wait until configuration is over before emitting it. This means the fact that you can't change the store outside of configuration is explicit. The configuration api callsstartConfiguring()
andfinishConfiguring()
on the store and the store will emit at the end.Rendering current story
The
StoryRenderer
will render the current story from the store wheneverRENDER_CURRENT_STORY
is called. It will do the right thing whatever the state of the store is.The store will emit that event when it thinks it is ready to renderer:
It will then call it whenever the selection changes (assuming configuration isn't in process).
Breaking changes
There's a new type
RenderContext
which is passed to therender
function of each framework. I pulled a few things out of it that I am pretty sure weren't being used and seemed like junk. This is definitely a BREAKING CHANGE. Seestorybook/lib/core/src/client/preview/types.ts
Lines 40 to 59 in c4a8c86
Note that
selectedKind
andselectedStory
are no longer on the above.Further improvements / bugs that aren't in this PR
We could design a proper "module" system on the preview side. Perhaps we could mirror the way it works on the manager side for consistency, or if we don't like that, we could do something clean. I suspect
client_api
should be the interface that everything goes through (rather than things calling into the store).It's kind of weird the way that storyshots expects
start.ts
to not create a channel (based on some checks of the userAgent) and then later sets a mocked channel. Is there a cleaner solution here that isn't so tailored for SS?config_api
could probably be pulled intoclient_api
Can we drop
setAddon
from client_api: RemovesetAddon
code聽#10008Global params + decorators have some fundamental issues on HMR: Clearing global decorators / parameters does not work properly on HMR聽#10005
I didn't implement async stories. We kind of want this in 6.0 (for
@storybook/server
) 馃し鈥嶁檪 : Support async stories聽#10009