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

Hook on leaveing a story #120

Closed
linonetwo opened this issue Jan 16, 2017 · 3 comments
Closed

Hook on leaveing a story #120

linonetwo opened this issue Jan 16, 2017 · 3 comments

Comments

@linonetwo
Copy link

Some component will change Orientation of device, so seems that we need a hook to revert the changing of Orientation on leaving a story.

@thani-sh
Copy link
Contributor

I think we should be able to do this with a decorator. The basic idea is to wrap the story with a component and run the hook function on componentWillUnmount

storiesOf('Button', module)
  .addDecorator(storyHook({
    componentWillUnmount() {
      // reset screen orientation
    }
  }))
  .add('story - 1', () => (
    <pre>STORY_1</pre>
  ))

@linonetwo
Copy link
Author

linonetwo commented Jan 22, 2017

That would be much more easy to use. I'm currently having to use redux to do this clean up work for every component.

storiesOf('LineChart', module)
  .addDecorator((getStory) => {
    const store = getNewStore();
    const token = 'e77b3f75-1daa-4ded-b52a-7bbd65f758f5';
    store.dispatch(STORYBOOK.request({ orientation: 'landscape' }));
    store.dispatch(LOGIN.request({ token, jump: false }));
    Orientation.lockToLandscape();
    Promise.delay(2000)
    .then(() => {
      store.dispatch(LOAD_LINE_CHART.request({ areaType: 'Company', jump: false }));
    });
    return (
      <Provider store={store}>
        {getStory()}
      </Provider>
    );
  })
  .add('initial', () => (
    <LineChart areaType="Company" />
  ));

Where STORYBOOK.request({ orientation: 'landscape' }) is an action creator for informing redux to do something special for storybook. If I don't pass orientation: 'landscape' to it, it will reset the orientation.

@ndelangen
Copy link
Contributor

Please open an issue over at the new repo if you're still experiencing this issue, thanks!

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

No branches or pull requests

3 participants