redux-observable-action
v0.0.7
Published
A RxJS-based Redux middleware that flow out actions for easy side-effect processing
Downloads
12
Maintainers
Readme
redux-observable-action
A RxJS-based Redux middleware that flow out actions for easy side-effect processing
Inspired by redux-observable
Usage
npm i redux-observable-action
import { test, expect } from 'vitest'
import { Action, applyMiddleware, legacy_createStore } from 'redux'
import { Observable } from 'rxjs'
import { createMiddleware } from 'redux-observable-action'
const reducer = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
default:
return state
}
}
const streamerMiddleware = createMiddleware()
const store = legacy_createStore(reducer, applyMiddleware(streamerMiddleware))
function rootStreamer(action$: Observable<Action>) {
return action$.subscribe(action => {
if (action.type === 'INCREMENT') {
// do something
}
})
}
streamerMiddleware.run(rootStreamer)
More
- observable-duck: In-depth combination of redux use, complete types