UNPKG

1.35 kBMarkdownView Raw
1# Storybook Channel
2
3Storybook Channel is similar to an EventEmitter.
4Channels are used with Storybook implementations to send/receive events between the Storybook Manager and the Storybook Renderer.
5
6```js
7class Channel {
8 addListener(type, listener) {}
9 addPeerListener(type, listener) {} // ignore events from itself
10 emit(type, ...args) {}
11 eventNames() {}
12 listenerCount(type) {}
13 listeners(type) {}
14 on(type, listener) {}
15 once(type, listener) {}
16 prependListener(type, listener) {}
17 prependOnceListener(type, listener) {}
18 removeAllListeners(type) {}
19 removeListener(type, listener) {}
20}
21```
22
23The channel takes a Transport object as a parameter which will be used to send/receive messages. The transport object should implement this interface.
24
25```js
26class Transport {
27 send(event) {}
28 setHandler(handler) {}
29}
30```
31
32Currently, channels are baked into storybook implementations and therefore this module is not designed to be used directly by addon developers. When developing addons, use the `getChannel` method exported by `@storybook/addons` module. For this to work, Storybook implementations should use the `setChannel` method before loading addons.
33
34```js
35import { addons } from '@storybook/addons';
36
37const channel = addons.getChannel();
38```
39
40* * *
41
42For more information visit: [storybook.js.org](https://storybook.js.org)