Skip to content

Commit

Permalink
Merge pull request #3036 from storybooks/tmeasday/use-client-api-in-r…
Browse files Browse the repository at this point in the history
…eact-native

Use client api in react native
  • Loading branch information
Hypnosphi authored Feb 20, 2018
2 parents b97b07b + f1c1d0c commit b6f5682
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 73 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
39 changes: 6 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,21 @@ 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
}

const fileName = module ? module.filename : null;

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

setAddon(addon) {
Object.assign(this._addons, addon);
}
this._stories = new StoryStore();
this._clientApi = new ClientApi({ storyStore: this._stories });

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

configure(loadStories, module) {
Expand All @@ -45,19 +31,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.

9 changes: 1 addition & 8 deletions lib/core/src/client/preview/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ const defaultDecorateStory = (getStory, decorators) =>
);

export default class ClientApi {
constructor({
channel,
storyStore = new StoryStore(),
decorateStory = defaultDecorateStory,
} = {}) {
// channel can be null when running in node
// always check whether channel is available
this._channel = channel;
constructor({ storyStore = new StoryStore(), decorateStory = defaultDecorateStory } = {}) {
this._storyStore = storyStore;
this._addons = {};
this._globalDecorators = [];
Expand Down

0 comments on commit b6f5682

Please sign in to comment.