Skip to content

Commit

Permalink
refactor(actionObserver): extract function
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Aug 27, 2023
1 parent 3eba3e3 commit f0be387
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/app/actionObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const matchType =
(action: Action): action is PayloadAction<TPayload> =>
actionCreator.match(action)

const getPayload = <TPayload>(action: PayloadAction<TPayload>): TPayload => action.payload

export const createActionObserver = (): ActionObserver => {
const action$ = new Subject<Action>()

Expand All @@ -25,10 +27,7 @@ export const createActionObserver = (): ActionObserver => {
}

const on: OnAction = actionCreator =>
action$.pipe(
filter(matchType(actionCreator)),
map(action => action.payload)
)
action$.pipe(filter(matchType(actionCreator)), map(getPayload))

return { middleware, on }
}

0 comments on commit f0be387

Please sign in to comment.