rxjs v6 / redux-observable v1.0.0:运算符未在史诗级中工作

时间:2018-09-20 09:16:22

标签: javascript reactjs react-redux redux-observable rxjs6

我正在使用最新版本的redux-observable和Rxjs,即

// 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' })
);

因此,当我第一次执行程序时,出现以下错误:

enter image description here

我用Google搜索它,然后found a solution here表示要安装rxjs-compat@6(但是这没有任何意义),我也安装了它!然后我遇到了以下错误:

enter image description here

我不知道我在哪里/哪里做错了?任何帮助将不胜感激!

谢谢

1 个答案:

答案 0 :(得分:2)

应该是

import { mapTo } from 'rxjs/operators';

代替

import { mapTo } from 'rxjs/operator/mapTo';

来源:https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md#usage