Skip to content

Commit def680f

Browse files
committed
Fix destructured mount in play
Addressed #270
1 parent 06dee29 commit def680f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/runtime/create-runtime-stories.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ export const createRuntimeStories = (Stories: Component, meta: Meta<Cmp>) => {
6868
* The 'play' function should be delegated to the real play Story function
6969
* in order to be run into the component scope.
7070
*/
71-
storyObj.play = (storyContext) => {
71+
function params(fn) { return fn.toString().match(/[^(]*\(([^)]*)/)?.slice(1) ?? [] }
72+
const isMounting = params(storyObj.play).filter((p) => /\{\s*mount\s*\}/.test(p) ).length != 0
73+
storyObj.play = isMounting ? function ({ mount }) { return playDelegator(arguments[0]) } : (storyContext) => playDelegator(storyContext);
74+
function playDelegator(storyContext) {
7275
const delegate = storyContext.playFunction?.__play;
7376

7477
if (delegate) {

0 commit comments

Comments
 (0)