Skip to content
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: Add JSDoc comments to manager-api APIs #22968

Merged
merged 16 commits into from
Jun 8, 2023
Prev Previous commit
Next Next commit
modules/channel
ndelangen committed Jun 7, 2023
commit 308807b75003db0d227c9e006a914d9e24bb8916
29 changes: 12 additions & 17 deletions code/lib/manager-api/src/modules/channel.ts
Original file line number Diff line number Diff line change
@@ -11,37 +11,32 @@ export interface SubAPI {
* @protected Please do not use, it's for internal use only.
*/
getChannel: () => API_Provider<API>['channel'];

/**
* Adds a listener to the channel for the given event type.
* Returns a function that can be called to remove the listener.
* @param type - The event type to listen for. If using a core event, import it from `@storybook/core-events`.
* @param cb - The callback function to be called when the event is emitted.
* @param handler - The callback function to be called when the event is emitted.
* @returns A function that can be called to remove the listener.
*/
on: (type: string, cb: Listener) => () => void;

on: (type: string, handler: Listener) => () => void;
/**
* Removes a listener from the channel for the given event type.
* @param type - The event type to remove the listener from. If using a core event, import it from `@storybook/core-events`.
* @param cb - The callback function to be removed.
* @param handler - The callback function to be removed.
*/
off: (type: string, cb: Listener) => void;

off: (type: string, handler: Listener) => void;
/**
* Emits an event on the channel for the given event type.
* @param type - The event type to emit. If using a core event, import it from `@storybook/core-events`.
* @param args - The arguments to pass to the event listener.
*/
emit: (type: string, ...args: any[]) => void;

/**
* Adds a one-time listener to the channel for the given event type.
* @param type - The event type to listen for. If using a core event, import it from `@storybook/core-events`.
* @param cb - The callback function to be called when the event is emitted.
* @param handler - The callback function to be called when the event is emitted.
*/
once: (type: string, cb: Listener) => void;

once: (type: string, handler: Listener) => void;
/**
* Emits an event to collapse all stories in the UI.
* @deprecated Use `emit(STORIES_COLLAPSE_ALL)` instead. This API will be removed in Storybook 8.0.
@@ -59,13 +54,13 @@ export type SubState = Record<string, never>;
export const init: ModuleFn<SubAPI, SubState> = ({ provider }) => {
const api: SubAPI = {
getChannel: () => provider.channel,
on: (type, cb) => {
provider.channel.addListener(type, cb);
on: (type, handler) => {
provider.channel.on(type, handler);

return () => provider.channel.removeListener(type, cb);
return () => provider.channel.off(type, handler);
},
off: (type, cb) => provider.channel.removeListener(type, cb),
once: (type, cb) => provider.channel.once(type, cb),
off: (type, handler) => provider.channel.off(type, handler),
once: (type, handler) => provider.channel.once(type, handler),
emit: (type, data, ...args) => {
if (
data?.options?.target &&
@@ -81,7 +76,7 @@ export const init: ModuleFn<SubAPI, SubState> = ({ provider }) => {
},

collapseAll: () => {
provider.channel.emit(STORIES_COLLAPSE_ALL, {});
api.emit(STORIES_COLLAPSE_ALL, {});
},
expandAll: () => {
api.emit(STORIES_EXPAND_ALL);