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

automatically strip play functions for react-native runtime #570

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/react-native/src/Start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,23 @@ export function prepareStories({
tags: ['story'],
};

importMap[`${root}/${filename.substring(2)}`] = req(filename);
const importedStories = req(filename);
const stories = Object.entries(importedStories).reduce(
(carry, [storyKey, story]: [string, Readonly<Record<string, unknown>>]) => {
if (story.play) {
// play functions are not supported on native. Instead of requiring consumers to
// guard their play functions with platform checks, we automatically strip any
// stories of their play functions for them.
carry[storyKey] = { ...story, play: undefined };
} else {
carry[storyKey] = story;
}
return carry;
},
{}
);

importMap[`${root}/${filename.substring(2)}`] = stories;
} else {
console.log(`Unexpected error while loading ${filename}: could not find title`);
}
Expand Down