Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

@SteveALee SteveALee Jan 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we can import the utils in core used to process {mount} so provided simplified equivalent

storyObj.play = isMounting ? function ({ mount }) { return playDelegator(arguments[0]) } : (storyContext) => playDelegator(storyContext);
Copy link
Contributor Author

@SteveALee SteveALee Jan 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used arguments as destructuring ...var rest and then spread to create object many miss any non own non enumerable props.

function playDelegator(storyContext) {
const delegate = storyContext.playFunction?.__play;

if (delegate) {
Expand Down