diff --git a/packages/core/media-store/src/factory.ts b/packages/core/media-store/src/factory.ts index 80bbdd48..5f89fd3c 100644 --- a/packages/core/media-store/src/factory.ts +++ b/packages/core/media-store/src/factory.ts @@ -31,7 +31,9 @@ export type FacadeProp = ReadonlyFacadeProp & { set: FacadeSetter; /** @TODO We probably need to refactor this for more complex cases where we can't simply translate to a setter */ actions: { - [k: string]: (val: CustomEvent) => ReturnType>; + [k: string]: ( + val: Pick, 'type' | 'detail'>, + ) => ReturnType>; }; }; @@ -49,7 +51,7 @@ export function createMediaStore({ media?: any; stateMediator: Partial & Pick; }) { - const stateOwners: any = {}; + const stateOwners: StateOwners = {}; const store = map({}); const stateUpdateHandlers: Record void> = {}; const keys = Object.keys(stateMediator); @@ -90,18 +92,23 @@ export function createMediaStore({ } return { - dispatch(action: any) { + dispatch(action: Pick, 'type' | 'detail'>) { const { type, detail } = action; if (type === 'mediaelementchangerequest') { updateStateOwners({ media: detail }); } else { for (const stateObject of Object.values(stateMediator).filter( - (stateMediator) => 'set' in stateMediator, + ( + stateMediatorEntry, + ): stateMediatorEntry is FacadeProp => + 'set' in stateMediatorEntry, )) { const { set, actions } = stateObject; - if (type in actions) { - set(actions[type as keyof typeof actions](), stateOwners); + if (actions[type]) { + const actionFn = actions[type]; + const actionValue = actionFn(action); + (set as FacadeSetter)(actionValue, stateOwners); } } }