0.0.3 • Published 4 years ago

fraud-redux-mapper v0.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Fraud Redux-Mapper

A Redux middleware that maps an action to some lambda.

Usage

To use this middleware, simply provide a table of ActionMap<S, A>[].

const store = createStore(
  reducer,
  applyMiddleware(
    createMapper([
      createActionMap('SOME_ACTION', (store) => {
        store.dispatch({ type: 'THIS_ACTION' })
      }),
      createActionMap('SOME_OTHER_ACTION', (store) => {
        store.dispatch({ type: 'THAT_ACTION' })
      }),
    ])
  )
)

Where the type signature for ActionMap<S, A>[] is,

export type ActionMap<S, A> = {
  from: A
  to: (a: MiddlewareAPI<Dispatch<AnyAction>, S>) => void
}

Or simply, it maps a certain action from to some function to that accepts the reducer.