From c71333b14be9c35f293801e8088f76607d641e1a Mon Sep 17 00:00:00 2001 From: Charles de Dreuille Date: Fri, 6 Oct 2023 13:38:41 +0100 Subject: [PATCH 1/2] Move channel outside of init --- code/lib/manager-api/src/modules/layout.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/code/lib/manager-api/src/modules/layout.ts b/code/lib/manager-api/src/modules/layout.ts index ce442e1af30d..a7d529868613 100644 --- a/code/lib/manager-api/src/modules/layout.ts +++ b/code/lib/manager-api/src/modules/layout.ts @@ -385,13 +385,12 @@ export const init: ModuleFn = ({ store, provider, singleStory const persisted = pick(store.getState(), 'layout', 'selectedPanel'); + provider.channel.on(SET_CONFIG, () => { + api.setOptions(merge(api.getInitialOptions(), persisted)); + }); + return { api, state: merge(api.getInitialOptions(), persisted), - init: () => { - provider.channel.on(SET_CONFIG, () => { - api.setOptions(merge(api.getInitialOptions(), persisted)); - }); - }, }; }; From f6de06b0b1577554e794fce2cf1187741a0a4af7 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Fri, 6 Oct 2023 16:06:59 +0200 Subject: [PATCH 2/2] fix test --- code/lib/manager-api/src/tests/layout.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/code/lib/manager-api/src/tests/layout.test.ts b/code/lib/manager-api/src/tests/layout.test.ts index 97c4c6c15628..a1891558ecda 100644 --- a/code/lib/manager-api/src/tests/layout.test.ts +++ b/code/lib/manager-api/src/tests/layout.test.ts @@ -1,5 +1,6 @@ import { themes } from '@storybook/theming'; import type { API_Provider } from 'lib/types/src'; +import EventEmitter from 'events'; import type { SubAPI, SubState } from '../modules/layout'; import type { SubState as AddonsSubState } from '../modules/addons'; import { defaultLayoutState, init as initLayout } from '../modules/layout'; @@ -33,7 +34,10 @@ describe('layout API', () => { return currentState as unknown as State; }), } as unknown as Store; - provider = { getConfig: jest.fn(() => ({})) } as unknown as API_Provider; + provider = { + getConfig: jest.fn(() => ({})), + channel: new EventEmitter(), + } as unknown as API_Provider; layoutApi = initLayout({ store, provider,