mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-17 05:02:23 +08:00
Wire in initial global Args
This commit is contained in:
parent
a86c083493
commit
569ec730d8
@ -112,6 +112,7 @@ export interface SetStoriesPayload {
|
||||
export interface SetStoriesPayloadV2 extends SetStoriesPayload {
|
||||
v: 2;
|
||||
error?: Error;
|
||||
globalArgs: Args;
|
||||
globalParameters: Parameters;
|
||||
kindParameters: {
|
||||
[kind: string]: Parameters;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { UPDATE_GLOBAL_ARGS, GLOBAL_ARGS_UPDATED } from '@storybook/core-events';
|
||||
import { SET_STORIES, UPDATE_GLOBAL_ARGS, GLOBAL_ARGS_UPDATED } from '@storybook/core-events';
|
||||
import { Args, ModuleFn } from '../index';
|
||||
import { SetStoriesPayloadV2 } from '../lib/stories';
|
||||
|
||||
export interface SubState {
|
||||
globalArgs: Args;
|
||||
@ -23,6 +24,9 @@ export const init: ModuleFn = ({ store, fullAPI }) => {
|
||||
|
||||
const initModule = () => {
|
||||
fullAPI.on(GLOBAL_ARGS_UPDATED, (globalArgs: Args) => store.setState({ globalArgs }));
|
||||
fullAPI.on(SET_STORIES, ({ globalArgs }: SetStoriesPayloadV2) =>
|
||||
store.setState({ globalArgs })
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import EventEmitter from 'event-emitter';
|
||||
import { UPDATE_GLOBAL_ARGS, GLOBAL_ARGS_UPDATED } from '@storybook/core-events';
|
||||
import { SET_STORIES, UPDATE_GLOBAL_ARGS, GLOBAL_ARGS_UPDATED } from '@storybook/core-events';
|
||||
|
||||
import { ModuleArgs, API } from '../index';
|
||||
import { init as initModule, SubAPI } from '../modules/globalArgs';
|
||||
@ -24,6 +24,21 @@ describe('stories API', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('set global args on SET_STORIES', () => {
|
||||
const api = EventEmitter();
|
||||
const store = createMockStore();
|
||||
const { state, init } = initModule(({ store, fullAPI: api } as unknown) as ModuleArgs);
|
||||
store.setState(state);
|
||||
init();
|
||||
|
||||
api.emit(SET_STORIES, { globalArgs: { a: 'b' } });
|
||||
expect(store.getState()).toEqual({ globalArgs: { a: 'b' } });
|
||||
|
||||
expect(state).toEqual({
|
||||
globalArgs: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('updates the state when the preview emits GLOBAL_ARGS_UPDATED', () => {
|
||||
const api = EventEmitter();
|
||||
const store = createMockStore();
|
||||
|
Loading…
x
Reference in New Issue
Block a user