Skip to content

Commit

Permalink
feat(core): added support for specifying multiple mutations in triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Apr 16, 2021
1 parent 2d060ed commit 8797e7b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ export function createStore<T extends object = any>(name: string, data: T, optio
};

const getMutationHook = (eventName: string) => {
return <TPayload = any, TResult = any>(mutationName: string, handler: MutationHookHandler<TPayload, TResult>) => {
return <TPayload = any, TResult = any>(mutationName: string | string[], handler: MutationHookHandler<TPayload, TResult>) => {
return store.on(eventName, (event?: EventPayload<MutationEventData<TPayload, TResult>>) => {
if (event && event.data.mutation === mutationName) {
if (event && ([] as string[]).concat(mutationName).includes(event.data.mutation)) {
handler(event.data);
}
})
Expand Down
6 changes: 3 additions & 3 deletions core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export interface Store<TState> extends StoreBase<TState> {
on(event: string, handler: EventHandler): EventListener;
once(event: string, handler: EventHandler): EventListener;
destroy(): void;
onBeforeMutation<TPayload = any, TResult = any>(mutationName: string, handler: MutationHookHandler<TPayload, TResult>): EventListener;
onAfterMutation<TPayload = any, TResult = any>(mutationName: string, handler: MutationHookHandler<TPayload, TResult>): EventListener;
onMutationError<TPayload = any, TResult = any>(mutationName: string, handler: MutationHookHandler<TPayload, TResult>): EventListener;
onBeforeMutation<TPayload = any, TResult = any>(mutationName: string | string[], handler: MutationHookHandler<TPayload, TResult>): EventListener;
onAfterMutation<TPayload = any, TResult = any>(mutationName: string | string[], handler: MutationHookHandler<TPayload, TResult>): EventListener;
onMutationError<TPayload = any, TResult = any>(mutationName: string | string[], handler: MutationHookHandler<TPayload, TResult>): EventListener;
};

export interface HarlemPlugin {
Expand Down

0 comments on commit 8797e7b

Please sign in to comment.