Skip to content

Commit

Permalink
Use the full ClientApi from @storybook/react-native
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Feb 20, 2018
1 parent add0964 commit 2bcb29c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 65 deletions.
1 change: 1 addition & 0 deletions app/react-native/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const preview = new Preview();
export const storiesOf = preview.storiesOf.bind(preview);
export const setAddon = preview.setAddon.bind(preview);
export const addDecorator = preview.addDecorator.bind(preview);
export const clearDecorators = preview.clearDecorators.bind(preview);
export const configure = preview.configure.bind(preview);
export const getStorybook = preview.getStorybook.bind(preview);
export const getStorybookUI = preview.getStorybookUI.bind(preview);
Expand Down
38 changes: 5 additions & 33 deletions app/react-native/src/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,20 @@ import parse from 'url-parse';
import addons from '@storybook/addons';
import createChannel from '@storybook/channel-websocket';
import { EventEmitter } from 'events';
import { StoryStore } from '@storybook/core/client';
import StoryKindApi from './story_kind';
import { StoryStore, ClientApi } from '@storybook/core/client';
import OnDeviceUI from './components/OnDeviceUI';
import StoryView from './components/StoryView';

export default class Preview {
constructor() {
this._addons = {};
this._decorators = [];
this._stories = new StoryStore();
this._events = new EventEmitter();
}

storiesOf(kind, module) {
if (module && module.hot) {
// TODO remove the kind on dispose
}
this._clientApi = new ClientApi({ storyStore: new StoryStore() });

const fileName = module ? module.filename : null;

return new StoryKindApi(this._stories, this._addons, this._decorators, kind, fileName);
}

setAddon(addon) {
Object.assign(this._addons, addon);
}

addDecorator(decorator) {
this._decorators.push(decorator);
['storiesOf', 'setAdd', 'addDecorator', 'clearDecorators', 'getStorybook'].forEach(method => {
this[method] = this._clientApi[method].bind(this._clientApi);
});
}

configure(loadStories, module) {
Expand All @@ -45,19 +30,6 @@ export default class Preview {
}
}

getStorybook() {
return this._stories.getStoryKinds().map(kind => {
const fileName = this._stories.getStoryFileName(kind);

const stories = this._stories.getStories(kind).map(name => {
const render = this._stories.getStory(kind, name);
return { name, render };
});

return { kind, fileName, stories };
});
}

getStorybookUI(params = {}) {
return () => {
let webUrl = null;
Expand Down
32 changes: 0 additions & 32 deletions app/react-native/src/preview/story_kind.js

This file was deleted.

0 comments on commit 2bcb29c

Please sign in to comment.