Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Add option to use storybook with more than one user #132

Merged
merged 7 commits into from
Mar 28, 2017
Merged

Add option to use storybook with more than one user #132

merged 7 commits into from
Mar 28, 2017

Conversation

Gongreg
Copy link
Contributor

@Gongreg Gongreg commented Mar 22, 2017

Add option to differentiate connected users

We really like what storybook has to offer. We are going to use it to host our styleguide examples. We didn't like option to use react native web, we wanted users to be able to feel components in their phone. But react-native-stylebook doesn't support more than one user at the time. That is why I added options necessary to be able to host react-native-storybook in server and allow users play with the components.

wix/react-native-storybook-example

Some work in progress, but in this gif you can see that we have one styleguide server running, two simulators and two browsers. User enters the code he sees (later on it could be QR code or anything else) and then he can play with his app without interupting others.

Two simulators, two browsers one server playing together

I've added some command parameters:

  • --reset-cache (simply passes option to react-native cli, when developing it sometimes makes difficult hard to debug, because it likes to cache things).
  • --skip-packager (skip react-native packager all together and start only storybook server).
  • --manual-id (tells storybook that now users should get custom id which they have to use in react-native app to connect to storybook. It allows to deploy storybook server to any host and tell users to download the app and enter code to play with it. If this flag is not passed, everything works same way as before. When user opens storybook he gets his own custom id and that id is sent through websocket query to be saved in server.).
  • --secured (Tells to use https/wss instead of http/ws).
  • --environment DEVELOPMENT/PRODUCTION (Which webpack config to use, production one disables hot reload/enables code minification).

Also one bug fixed:

Story view component unmounts its events listeners when it is not rendered anymore.

Sadly I had to insert one dependency (uuid). It was already a dependency of some other your used package. In my opinion it is not that bad, because this id thing could be a core feature of react-native-storybook.

How things work:

If you don't use --manual-id option, everything works same way as before.
When you apply --manual-id option when running script, every time someone opens a storybook they will get uniq Id (it is random, so there is a chance of collision, but it shouldn't be a problem).
That uniqId is sent through websocket query to server (ws://localhost:7007/pairedId=1234).
When any event happens and a new data is being sent through websocket data will be only sent to other browsers/phones who also have pairedId=1234.

I have also added example screen to enter code in react-native in example project. Same thing happens in phone, you enter code, it is set through query. If you want to look into things more closely, there is a readme file inside example project. Also it is not very big, so it shouldn't take long time to look into contents inside it.

--reset-cache (simply passes option to react-native cli, when developing it sometimes makes difficult hard to debug, because it likes to cache things).
--skip-packager (skip react-native packager all together and start only storybook server).
--manual-id (tells storybook that now users should get custom id which they have to use in react-native app to connect to storybook. It allows to deploy storybook server to any host and tell users to download the app and enter code to play with it. If this flag is not passed, everything works same way as before. When user opens storybook he gets his own custom id and that id is sent through websocket query to be saved in server.).

Story view component unmounts its events listeners when it is not rendered anymore.
@Gongreg
Copy link
Contributor Author

Gongreg commented Mar 22, 2017

If somebody is going to be interested, we will try to add example project to github in few days.

const host = params.host || 'localhost';
const port = params.port || 7007;
const url = `ws://${host}:${port}`;
const url = `ws://${host}:${port}/${params.query}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

If params.query is not set, the url will have /undefined in the end. Better set it to an empty string if it's not set.

const query = params.query || '';
const url = `ws://${host}:${port}/${query}`;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, thanks :)

@thani-sh
Copy link
Contributor

Hi @Gongreg
I think this will be a useful feature. Can you add a simple step-by-step guide on how to use it including adding the --manual-id, starting react-native packagers and setting the id in the mobile app.

@Gongreg
Copy link
Contributor Author

Gongreg commented Mar 23, 2017

Hey, today I will upload example project with readme about running the project.

@Gongreg
Copy link
Contributor Author

Gongreg commented Mar 23, 2017

@mnmtanish Updated the initial comment, added example project. I will be waiting for your response.

@Gongreg
Copy link
Contributor Author

Gongreg commented Mar 27, 2017

Hey, so what is going to happen next? Do I need to do something or I can just wait for PR to go into the master?

@thani-sh thani-sh merged commit b0275d5 into storybook-eol:master Mar 28, 2017
@thani-sh
Copy link
Contributor

Hi @Gongreg, just released v2.3.0 with this feature.

@Gongreg
Copy link
Contributor Author

Gongreg commented Mar 28, 2017

Thank you very much :).
By any chance maybe you also work with @kadira/storybook-addon-knobs ? I created a PR over there. And I also see that @mthuret is working in storybooks team. She has a repo storybook-addon-usage. Maybe by any chance you can also ping her to look into it? I just don't want to create seperate repos doing same thing as existing ones.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants