Skip to content

Commit

Permalink
Typing for event payload
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Jul 10, 2022
1 parent 6386221 commit 2651299
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 16 additions & 4 deletions lib/instrumenter/src/instrumenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ import {
} from '@storybook/core-events';
import global from 'global';

import { Call, CallRef, CallStates, ControlStates, LogItem, Options, State } from './types';
import {
Call,
CallRef,
CallStates,
ControlStates,
LogItem,
Options,
State,
SyncPayload,
} from './types';

export const EVENTS = {
CALL: 'instrumenter/call',
Expand Down Expand Up @@ -251,7 +260,8 @@ export class Instrumenter {
acc[storyId] = Object.assign(getInitialState(), retainedState);
return acc;
}, {} as Record<StoryId, State>);
this.channel.emit(EVENTS.SYNC, { controlStates: controlsDisabled, logItems: [] });
const payload: SyncPayload = { controlStates: controlsDisabled, logItems: [] };
this.channel.emit(EVENTS.SYNC, payload);
global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__ = this.state;
}

Expand Down Expand Up @@ -558,7 +568,8 @@ export class Instrumenter {

const hasActive = logItems.some((item) => item.status === CallStates.ACTIVE);
if (debuggerDisabled || isLocked || hasActive || logItems.length === 0) {
this.channel.emit(EVENTS.SYNC, { controlStates: controlsDisabled, logItems });
const payload: SyncPayload = { controlStates: controlsDisabled, logItems };
this.channel.emit(EVENTS.SYNC, payload);
return;
}

Expand All @@ -574,7 +585,8 @@ export class Instrumenter {
end: isPlaying,
};

this.channel.emit(EVENTS.SYNC, { controlStates, logItems, pausedAt });
const payload: SyncPayload = { controlStates, logItems, pausedAt };
this.channel.emit(EVENTS.SYNC, payload);
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/instrumenter/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export interface LogItem {
parentId?: Call['id'];
}

export interface Payload {
export interface SyncPayload {
controlStates: ControlStates;
logItems: LogItem[];
pausedAt?: Call['id'];
}

export interface State {
Expand Down

0 comments on commit 2651299

Please sign in to comment.