-
-
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
Feature: serverChannel API #22892
Feature: serverChannel API #22892
Conversation
Add listening capability to serverChannel on node's side Fix data/args handling from serverChannel
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.
Looks good to me.
Small feedback on the API:
- Would it make sense to call it
emit/onServer
instead ofemit/onServerAction
, given that the existing is not calledemitAction
- Should we have feature parity with the regular channel, so also have
offServer
,onceServer
,getServerChannel
?
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.
Can we abstract it so that there is only one channel? This feels like yet another concept to have to educate addon authors about. Instead, addons could differentiate based on the event type.
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 with @shilman it would be best to abstract the two channels each context now has into a single "multiplexing" channel. But in the meantime, let's work to make the server channel as consistent as possible with the existing "manager<->preview" channel.
I agree with Michael, if it's possible to get the same channel, then we get a nice API for addon authors, plus we get the already working mechanisms of |
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.
This mostly LGTM. I'm a little unsure about the API naming, apart from that I agree with the approach so far.
@@ -8,8 +8,10 @@ import type { API, ModuleFn } from '../index'; | |||
export interface SubAPI { | |||
getChannel: () => API_Provider<API>['channel']; |
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.
Should we have getServerChannel
also? What about equivalents of off
, once
, etc?
I find the names onServerAction
and emitServerAction
kind of awkward. What about adding an extra argument to the other functions on('server', 'event', ...)
or similar? Is that too confusing?
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.
@tmeasday I propose we do this, then later merge the 2 channels, and when we do that completely drop onServerAction
and emitServerAction
entirely.
So in the future .on
will simply listen to both, and .emit
will emit to both.
I don't want to do that today, because it would complicate/delay.
@@ -29,7 +29,7 @@ export async function storybookDevServer(options: Options) { | |||
options.presets.apply<CoreConfig>('core'), | |||
]); | |||
|
|||
const serverChannel = getServerChannel(server); | |||
const serverChannel = await options.presets.apply('serverChannel', getServerChannel(server)); |
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.
This is the "trick" to get (and possibly even modify/extend, the serverChannel: It's now a presetProperty.
This means addon creators can add a preset.js
and add:
import { Channel } from '@storybook/channels';
export const serverChannel = async (channel: Channel) => {
// do something with the channel
return channel;
}
@JReinhold @shilman I just wanted to have something that's simple and work for now, minimal approach, prove it works. Assuming we'll later work on merging the 2 channels, do we want to add 3 more API-methods? I'm happy to make changes, do you feel particularly strong about this? |
# Conflicts: # code/lib/core-server/package.json # code/yarn.lock
merging the 2 channels would involve:
It can be done, for sure. And I think we should do it eventually. I decided to give it a try anyway: |
…cts to both. leave serverChannel to point to main channel for backwards compatibility
…channels experiment with universal channel
I'm going to close this and re-open a PR based on the same branch, so have the conversation make sense. |
Introduce a new API for storybook code:
An API to send messages to and from the serverChannel from addons.
Addons can connect to the serverChannel both in
manager.ts
and frompreset.ts
files, allowing an addon to do bi-directional communication.This is very useful for addons that want to do some work in node, like let's say:
main.ts
)Changes: