redux-handler
Powerful 💪 and simple 👈 redux middleware to handle async actions.
Table of Contents
Requirements
peer dependencies: redux: ^4
optional dependencies: rxjs: ^6
Installation
store/index.ts
// Define your inner stores // Combine it
store/handler.ts
Usage
Define store & handler:
// Create action .action // For arguments use `.action<TArgs>` .pipe // Operators
Operators
Each pipe must contain single main operator
Main
sync
Handles standard action handler. Compatible operators: Common
synctypeof state
rx
Handles rxjs observable. Compatible operators: Common, Async
rxObservable
promise
Handles promise. Compatible operators: Common, Async
promisePromise
thunk
Handles async dispatch. Compatible operators: Common
thunk void
Async
pending
Occurs before async method is called.
pendingvoid
fulfilled
Occurs on async method succeeds.
fulfilledtypeof state
rejected
Occurs on async method failed.
rejectedtypeof state
completed
Occurs after async method is completed.
completedtypeof state
loading
Sets the property = true
on pending.
Sets the property = false
on completed.
loadingprop: keyof state
Common
available
Prevents calling actions based on state. Can be used only before main operator.
availableboolean
Advanced
Handle action in another handler
myHandler.handle myAction, // ...operators[]
Redux devtools
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : compose
Examples
Simple users fetch:
.action .pipe availablegetState.users.data, rxajax, fulfilled, loading'loading'
Dispatch another action inside action:
.action .pipe sync .action .pipe rxconcat ajax, ofupdateUsersBalance
Development
Publishing
npm run build
npm publish dist