mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
updated config name, added comment, fixed tests
This commit is contained in:
parent
23da639ffc
commit
7753bfac80
@ -5,11 +5,14 @@ import ClientApi from './client_api';
|
|||||||
import ConfigApi from './config_api';
|
import ConfigApi from './config_api';
|
||||||
import StoryStore from './story_store';
|
import StoryStore from './story_store';
|
||||||
|
|
||||||
const getContext = ({ decorateStory = undefined, disableAddStoryDispose = false } = {}) => {
|
const getContext = ({
|
||||||
|
decorateStory = undefined,
|
||||||
|
noStoryModuleAddMethodHotDispose = false,
|
||||||
|
} = {}) => {
|
||||||
const channel = mockChannel();
|
const channel = mockChannel();
|
||||||
addons.setChannel(channel);
|
addons.setChannel(channel);
|
||||||
const storyStore = new StoryStore({ channel });
|
const storyStore = new StoryStore({ channel });
|
||||||
const clientApi = new ClientApi({ storyStore, decorateStory, disableAddStoryDispose });
|
const clientApi = new ClientApi({ storyStore, decorateStory, noStoryModuleAddMethodHotDispose });
|
||||||
const { clearDecorators } = clientApi;
|
const { clearDecorators } = clientApi;
|
||||||
const configApi = new ConfigApi({ clearDecorators, storyStore, channel, clientApi });
|
const configApi = new ConfigApi({ clearDecorators, storyStore, channel, clientApi });
|
||||||
|
|
||||||
@ -559,20 +562,20 @@ describe('preview.client_api', () => {
|
|||||||
|
|
||||||
storiesOf('kind', module).add('story', jest.fn());
|
storiesOf('kind', module).add('story', jest.fn());
|
||||||
|
|
||||||
expect(module.hot.dispose.calls.length).toEqual(2);
|
expect(module.hot.dispose.mock.calls.length).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not bind dispose inside add when disableAddStoryDispose is true', () => {
|
it('should not call `module.hot.dispose` inside add when noStoryModuleAddMethodHotDispose is true', () => {
|
||||||
const module = new MockModule();
|
const module = new MockModule();
|
||||||
module.hot.dispose = jest.fn();
|
module.hot.dispose = jest.fn();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
clientApi: { storiesOf, getStorybook },
|
clientApi: { storiesOf, getStorybook },
|
||||||
} = getContext({ disableAddStoryDispose: true });
|
} = getContext({ noStoryModuleAddMethodHotDispose: true });
|
||||||
|
|
||||||
storiesOf('kind', module).add('story', jest.fn());
|
storiesOf('kind', module).add('story', jest.fn());
|
||||||
|
|
||||||
expect(module.hot.dispose.calls.length).toEqual(1);
|
expect(module.hot.dispose.mock.calls.length).toEqual(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -92,12 +92,12 @@ export default class ClientApi {
|
|||||||
constructor({
|
constructor({
|
||||||
storyStore,
|
storyStore,
|
||||||
decorateStory = defaultDecorateStory,
|
decorateStory = defaultDecorateStory,
|
||||||
disableAddStoryDispose,
|
noStoryModuleAddMethodHotDispose,
|
||||||
}: ClientApiParams) {
|
}: ClientApiParams) {
|
||||||
this._storyStore = storyStore;
|
this._storyStore = storyStore;
|
||||||
this._addons = {};
|
this._addons = {};
|
||||||
|
|
||||||
this._disableAddStoryDispose = disableAddStoryDispose || false;
|
this._disableAddStoryDispose = noStoryModuleAddMethodHotDispose || false;
|
||||||
|
|
||||||
this._decorateStory = decorateStory;
|
this._decorateStory = decorateStory;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user