Skip to content

Commit

Permalink
comment why we hardcode SET_CURRENT_STORY
Browse files Browse the repository at this point in the history
  • Loading branch information
michalziolkowski committed Oct 23, 2024
1 parent 9a58d34 commit 2eedaa2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { getAddons } from '../utils/storybookImports';
import { getAddons, SET_CURRENT_STORY } from '../utils/storybookImports';

function useStoryEmitter(updateRenderedStoryId: (storyId: string) => void): (id: string) => void {
useEffect(() => {
Expand All @@ -10,7 +10,7 @@ function useStoryEmitter(updateRenderedStoryId: (storyId: string) => void): (id:

const initialize = async (): Promise<void> => {
const _channel = await getAddons().ready();
_channel.on('setCurrentStory', handleStoryRendered);
_channel.on(SET_CURRENT_STORY, handleStoryRendered);
};

setTimeout(() => initialize(), 500);
Expand All @@ -19,9 +19,9 @@ function useStoryEmitter(updateRenderedStoryId: (storyId: string) => void): (id:

return async (storyId: string) => {
const _channel = await getAddons().ready();
_channel.emit('setCurrentStory', { storyId });
_channel.emit(SET_CURRENT_STORY, { storyId });
// if we don't call it twice going back from preview to original mode doesn't work
_channel.emit('setCurrentStory', { storyId });
_channel.emit(SET_CURRENT_STORY, { storyId });
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ try {
}

export const getAddons = (): any => addonsV8 ?? addonsV7;

// This was originally imported from:
// - @storybook/core-events in Storybook 7
// - @storybook/core/core-events in Storybook 8
// We keep it hardcoded as some users didn't have dependency in their versions of the library.
export const SET_CURRENT_STORY = 'setCurrentStory';

0 comments on commit 2eedaa2

Please sign in to comment.