I've been trying to integrate Vulcan.js, a Meteor framework, with Storybook. The difficulty comes from the differences in build system. Currently, we are able to load some specific Meteor packages in Storybook using Webpack.
So, now we need to mimick some additional Meteor features in Storybook. We rely on a
Meteor.startup() callback to initialize a specific React component that is a registry of other components. However I can't find any equivalent pattern in Storybook.
The characteristic of a callback registered with
Meteor.startup() are as following:
- it is run
afterthe app is build. So it is not possible to just write a "startup" file and import it, because it will run too soon, the registry will still be empty
- it is run
beforestories are actually rendered or loaded. Basically
Meteor.startupcallbacks are guaranteed to be the first function to be run. So calling relevant function in a decorator may be too late.
- it is called only once. This is not a strong requirement as we can bypass it by writing callbacks as pure function but it's better to avoid multiple calls.
I've tried writing an addon, but it does not work as addons have their own build system. Therefore they can't access our Meteor packages and yet they need them to work correctly.
I've tried writing a decorator. That's an okay solution but I have strange behaviour, because it runs the startup function on every component mount (that's the only way to run them after import but before render). That's my best bet currently but it seems suboptimal.
Last solution is running the code at the top of relevant stories. It works but it's error prone and affects the developer experience
So, here is the question: how would you define a callback in Storybook so that it is run during startup, like
Meteor.startup callbacks do?