Skip to content

Commit

Permalink
Fix destructured mount in play
Browse files Browse the repository at this point in the history
Addressed storybookjs#270
  • Loading branch information
SteveALee committed Jan 25, 2025
1 parent 06dee29 commit def680f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/runtime/create-runtime-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export const createRuntimeStories = (Stories: Component, meta: Meta<Cmp>) => {
* The 'play' function should be delegated to the real play Story function
* in order to be run into the component scope.
*/
storyObj.play = (storyContext) => {
function params(fn) { return fn.toString().match(/[^(]*\(([^)]*)/)?.slice(1) ?? [] }
const isMounting = params(storyObj.play).filter((p) => /\{\s*mount\s*\}/.test(p) ).length != 0
storyObj.play = isMounting ? function ({ mount }) { return playDelegator(arguments[0]) } : (storyContext) => playDelegator(storyContext);
function playDelegator(storyContext) {
const delegate = storyContext.playFunction?.__play;

if (delegate) {
Expand Down

0 comments on commit def680f

Please sign in to comment.