我完全遵循文档,并且总是得到
动作必须是普通对象
如果我将applyMiddleware
放到epicMiddleware
中,则一切正常
// src/store/index.js
import { createStore, combineReducers, applyMiddleware } from 'redux'
import { createEpicMiddleware, combineEpics } from 'redux-observable'
import thunk from 'redux-thunk'
import users from './users/reducer'
import countEpic from './users/epics'
const epicMiddleware = createEpicMiddleware()
const store = createStore(
combineReducers({
users,
}),
applyMiddleware(thunk, epicMiddleware)
)
epicMiddleware.run(combineEpics(countEpic))
export default store
// src/store/users/epics.js
import { mapTo } from 'rxjs/operators'
import { ofType } from 'redux-observable'
const countEpic = action$ =>
action$.pipe(
ofType('CLICK'),
mapTo({ type: 'INCREMENT' })
)
export default countEpic