How to use the @storybook/addons.getDatabase function in @storybook/addons

To help you get started, we’ve selected a few @storybook/addons examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github storybookjs / storybook / addons / comments / src / manager / containers / CommentsPanel / index.js View on Github external
componentDidMount() {
    const db = addons.getDatabase();
    this.store = new DataStore(db);
    this.stopListeningToComments = this.store.onComments(comments => {
      this.setState({ comments });
    });

    // Clear the current notes on every story change.
    this.stopListeningOnStory = this.props.api.onStory((kind, story) => {
      // set the current selection
      this.store.setCurrentStory(kind, story);
    });

    this.stopListingStoreLoading = this.store.onLoading(loading => {
      this.setState({ loading });
    });

    this.init();
github storybookjs / storybook / addons / comments / src / manager / containers / CommentsPanel / index.js View on Github external
init() {
    const db = addons.getDatabase();

    if (typeof db.persister.getUser !== 'function') {
      throw new Error('unable to get user info');
    }

    this.setState({ loading: true });
    db.persister
      .getUser()
      .then(u => Promise.resolve(u), () => Promise.resolve(null))
      .then(user => {
        if (user) {
          this.store.setCurrentUser(user);
          this.setState({ user });
        } else {
          this.setState({ user: null });
        }