redux-repatch
Redux enhancer for dispatching reducers
Repatch is just a simplfied Redux, that let you create actions more briefly by dispatching reducers directly. However if you would like to use redux with this feature, you need this package.
Installation
npm install --save redux-repatch
How to use
redux-repatch
provides a store enhancer, that is usable at creating the store. This enhancer ensures that you can use regular actions and repatch actions together:
const reducer = state = 0 action const store = const setToValue = type: 'SET_TO_VALUE' value // redux actionconst increment = state + value // repatch action store // 42store // 52
Use with other enhancers
const store =
redux-thunk
Use withWe cannot use repatch
actions and thunk
actions together, because both of actions are defined as functions. Therefore redux-repatch
provides a builtin thunk
mechanism.
The original repatch library shares its own thunk
middleware, that's using is optional. redux-repatch
does it automatically.
In the repatch
terminology thunk
reducer is a function, that returns a function. We call this function as the delegate
.
const waitAndIncrement = async { await ; } store
However if you would like to use with the original redux-thunk, then you are looking for this: redux-repatch-creator.
Injecting extra argument
; const store = const updateUser = async { // ... }
How it works
The repatch
enhancer extends your reducer by handling a special action type, and enhances the store
with a middleware. This middleware handles the function-like actions. The thunk
actions will fired in the middleware and they returned value will be returned. The regular repatch
reducers will be transformed to regular redux
action objects with the previously mentioned special action type. Then the extended reducer can handle it.
Import in CommonJS
const repatch = repatch
or
const repatch = default
Bundles
or the minified bundle:
then
const repatch = ReduxRepatchrepatch