![](/img/trans.png)
[英]How can I chain RxJS observable in a redux-observable epic?
[英]rxjs v6 / redux-observable v1.0.0: Operators not working in epic
我使用的是最新版本的redux-observable和Rxjs ie
// My version
"redux-observable": "^1.0.0",
"rxjs": "^6.3.2"
商店 - 中間件,設置如下:
// Setting up middlewares
import { pingEpic } from './epics';
import pingReducer from './reducers/pingReducer';
import { combineReducers, createStore, applyMiddleware } from 'redux';
import { combineEpics, createEpicMiddleware } from 'redux-observable';
const rootReducer = combineReducers(pingReducer);
const rootEpic = combineEpics(pingEpic);
const epicMiddleware = createEpicMiddleware();
const store = createStore(rootReducer,
applyMiddleware(epicMiddleware)
);
epicMiddleware.run(rootEpic);
export default store;
我的史詩看起來像這樣
// pingEpic.js
import { mapTo } from 'rxjs/operator/mapTo';
import { ofType } from 'redux-observable';
export const pingEpic = action$ => action$.pipe(
ofType('PING'),
mapTo({ type: 'PONG' })
);
因此,當我第一次執行該程序時,我收到以下錯誤:
我用Google搜索並找到一個解決方案 ,說安裝rxjs-compat@6
(但它沒有任何意義)我也安裝了它! 然后我遇到了以下錯誤:
我不知道我做錯了什么/哪里? 任何幫助將非常感激!
謝謝
它應該是
import { mapTo } from 'rxjs/operators';
代替
import { mapTo } from 'rxjs/operator/mapTo';
來源: https : //github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md#usage
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.