Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Nov 29, 2023
1 parent 0db9c48 commit 5a33607
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 53 deletions.
2 changes: 2 additions & 0 deletions code/lib/manager-api/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ function ManagerConsumer<P = Combo>({
const comboData = filterer.current(managerContext);

const comboDataArray = useMemo(() => {
// @ts-expect-error (No overload matches this call)
return [...Object.entries(comboData).reduce((acc, keyval) => acc.concat(keyval), [])];
}, [managerContext.state]);

Expand Down Expand Up @@ -412,6 +413,7 @@ export function useSharedState<S>(stateId: string, defaultState?: S) {

useEffect(() => {
if (quicksync) {
// @ts-expect-error (Argument of type 'S | undefined' is not assignable)
api.setAddonState<S>(stateId, defaultState);
}
}, [quicksync]);
Expand Down
2 changes: 2 additions & 0 deletions code/lib/manager-api/src/lib/store-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { parse, stringify } from 'telejson';
// setting up the store, overriding set and get to use telejson
export default (_: any) => {
_.fn('set', function (key: string, data: object) {
// @ts-expect-error('this' implicitly has type 'any')
return _.set(this._area, this._in(key), stringify(data, { maxDepth: 50 }));
});
_.fn('get', function (key: string, alt: string) {
// @ts-expect-error('this' implicitly has type 'any')
const value = _.get(this._area, this._in(key));
return value !== null ? parse(value) : alt || value;
});
Expand Down
1 change: 0 additions & 1 deletion code/lib/manager-api/src/lib/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {
API_HashEntry,
SetStoriesPayload,
StoryIndexV2,
Renderer,
} from '@storybook/types';
// eslint-disable-next-line import/no-cycle
import { type API, combineParameters, type State } from '../index';
Expand Down
10 changes: 5 additions & 5 deletions code/lib/manager-api/src/modules/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export const init: ModuleFn<SubAPI, SubState> = ({ provider }) => {
const api: SubAPI = {
getChannel: () => provider.channel,
on: (type, handler) => {
provider.channel.on(type, handler);
provider.channel?.on(type, handler);

return () => provider.channel.off(type, handler);
return () => provider.channel?.off(type, handler);
},
off: (type, handler) => provider.channel.off(type, handler),
once: (type, handler) => provider.channel.once(type, handler),
off: (type, handler) => provider.channel?.off(type, handler),
once: (type, handler) => provider.channel?.once(type, handler),
emit: (type, data, ...args) => {
if (
data?.options?.target &&
Expand All @@ -73,7 +73,7 @@ export const init: ModuleFn<SubAPI, SubState> = ({ provider }) => {
? `storybook-ref-${data.options.target}`
: 'storybook-preview-iframe';
}
provider.channel.emit(type, data, ...args);
provider.channel?.emit(type, data, ...args);
},
collapseAll: () => {
api.emit(STORIES_COLLAPSE_ALL, {});
Expand Down
10 changes: 5 additions & 5 deletions code/lib/manager-api/src/modules/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export interface SubAPI {
export const init: ModuleFn<SubAPI, SubState> = ({ store, fullAPI, provider }) => {
const api: SubAPI = {
getGlobals() {
return store.getState().globals;
return store.getState().globals as Globals;
},
getGlobalTypes() {
return store.getState().globalTypes;
return store.getState().globalTypes as GlobalTypes;
},
updateGlobals(newGlobals) {
// Only emit the message to the local ref
provider.channel.emit(UPDATE_GLOBALS, {
provider.channel?.emit(UPDATE_GLOBALS, {
globals: newGlobals,
options: {
target: 'storybook-preview-iframe',
Expand All @@ -62,7 +62,7 @@ export const init: ModuleFn<SubAPI, SubState> = ({ store, fullAPI, provider }) =
}
};

provider.channel.on(
provider.channel?.on(
GLOBALS_UPDATED,
function handleGlobalsUpdated(this: any, { globals }: { globals: Globals }) {
const { ref } = getEventMetadata(this, fullAPI)!;
Expand All @@ -78,7 +78,7 @@ export const init: ModuleFn<SubAPI, SubState> = ({ store, fullAPI, provider }) =
);

// Emitted by the preview on initialization
provider.channel.on(
provider.channel?.on(
SET_GLOBALS,
function handleSetStories(this: any, { globals, globalTypes }: SetGlobalsPayload) {
const { ref } = getEventMetadata(this, fullAPI)!;
Expand Down
2 changes: 1 addition & 1 deletion code/lib/manager-api/src/modules/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export const init: ModuleFn<SubAPI, SubState> = ({ store, provider, singleStory

const persisted = pick(store.getState(), 'layout', 'selectedPanel');

provider.channel.on(SET_CONFIG, () => {
provider.channel?.on(SET_CONFIG, () => {
api.setOptions(merge(api.getInitialOptions(), persisted));
});

Expand Down
1 change: 1 addition & 0 deletions code/lib/manager-api/src/modules/refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export const init: ModuleFn<SubAPI, SubState> = (
)
: storyIndex;

// @ts-expect-error (could be undefined)
index = transformStoryIndexToStoriesHash(storyIndex, {
provider,
docsOptions,
Expand Down
2 changes: 1 addition & 1 deletion code/lib/manager-api/src/modules/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export const init: ModuleFn = ({ store, fullAPI, provider }) => {
});

// Also listen to keydown events sent over the channel
provider.channel.on(PREVIEW_KEYDOWN, (data: { event: KeyboardEventLike }) => {
provider.channel?.on(PREVIEW_KEYDOWN, (data: { event: KeyboardEventLike }) => {
api.handleKeydownEvent(data.event);
});
};
Expand Down
Loading

0 comments on commit 5a33607

Please sign in to comment.