-
(inspired by discussions in #9828 ) Is the only thing that matters as far as being "statically analyzable" that you can have the 1 default export, and then the export-per-story? i.e. if the code for a story file was
is that enough? Or does any more of it have to be there directly in the source code at the point of export? Right now we don't need the v7 store yet, but since future versions will eventually make it required, get rid of storiesOf, etc, it seems worthwhile to understand the requirements a bit more. Right now we're using an API that wraps Also what does being statically-analyzable enable, anyways? Why does anything except the default export need to be statically-analyzable, since IIUC it is some sort of perf improvement to not load all stories at once, but one only needs to know the module names (to generate the non-leaves of the tree) right? So why couldn't we have something like
to get a convenient API without having to build things for combinatorics, json, etc. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
@Jamie5 i don't have a succinct answer and it will probably change, but here's a first attempt. When Storybook starts it reads in all the story files and analyzes their contents but does not evaluate their contents. Consider a file The reason we can't dynamically add stories per your example MetaThe default export should be an object expression or a variable that references an object expression. If you use title, it should be a field in that object and the value should be a string literal. Validexport default {}; export default { title: 'foo' }; const meta = { title: 'foo' };
export default meta; Invalidexport default metaFn(); export default { title: `baz` }; const a = { title: 'moo' };
const b = a;
export default b; StoriesEach story should be a named export that should either be a function or an object. We can probably loosen the requirements on this. If you use the Validexport const Foo = () => { /** anything **/ }; export const Bar = { /** anything **/ }; export const Baz = Template.bind({}); const Foo = () => { /** anything **/ };
export const Moo = Foo; export const Foo = () => { /** anything **/ };
Foo.storyName = 'foo'; export const Bar = { name: 'bar', /** anything **/ }; |
Beta Was this translation helpful? Give feedback.
@Jamie5 i don't have a succinct answer and it will probably change, but here's a first attempt.
When Storybook starts it reads in all the story files and analyzes their contents but does not evaluate their contents. Consider a file
Button.stories.js
. To analyze its contents we just need to read a single file. To evaluate the contents (i.e. execute the JS in the file) we need to read that file, every file that it depends on, and so on, which is much slower. We use that analysis to build a file calledstories.json
, which is an index of every story/doc in the project. This is used to fill in the sidebar in Storybook's UI. So, for the most part, it's mostly the data in the sidebar that we car…