Skip to content

Commit

Permalink
Merge pull request #1481 from mattleff/fixes-877
Browse files Browse the repository at this point in the history
Fixes #877, #879
  • Loading branch information
shilman authored Jul 22, 2017
2 parents bb7ce26 + 66f2546 commit 31255e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/react/src/client/preview/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class ClientApi {
this._storyStore = storyStore;
this._addons = {};
this._globalDecorators = [];
this._storiesAdded = false;
}

setAddon(addon) {
Expand All @@ -18,6 +19,9 @@ export default class ClientApi {
}

addDecorator(decorator) {
if (this._storiesAdded) {
throw new Error('Global decorators added after loading stories will not be applied');
}
this._globalDecorators.push(decorator);
}

Expand Down Expand Up @@ -51,6 +55,8 @@ export default class ClientApi {
});

api.add = (storyName, getStory) => {
this._storiesAdded = true;

if (typeof storyName !== 'string') {
throw new Error(`Invalid or missing storyName provided for a "${kind}" story.`);
}
Expand Down
10 changes: 10 additions & 0 deletions app/react/src/client/preview/client_api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ describe('preview.client_api', () => {
expect(storyStore.stories[0].fn()).toBe('bb-Hello');
});

it('should throw on adding global decorators after stories', () => {
const storyStore = new StoryStore();
const api = new ClientAPI({ storyStore });
const localApi = api.storiesOf('none');
localApi.add('storyName', () => 'Hello');
expect(() => {
api.addDecorator(fn => `bb-${fn()}`);
}).toThrow('Global decorators added after loading stories will not be applied');
});

it('should utilize both decorators at once', () => {
const storyStore = new StoryStore();
const api = new ClientAPI({ storyStore });
Expand Down

0 comments on commit 31255e5

Please sign in to comment.