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

Fix destructured mount in play #271

Open
wants to merge 7 commits into
base: next
Choose a base branch
from
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
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
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