简体   繁体   中英

rxjs v6 / redux-observable v1.0.0: Operators not working in epic

I am using the latest version of redux-observable and Rxjs ie

// My version
"redux-observable": "^1.0.0",
"rxjs": "^6.3.2"

The store - middleware, setup looks like this:

// 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;

And my epic looks like this

// pingEpic.js
import { mapTo } from 'rxjs/operator/mapTo';
import { ofType } from 'redux-observable';
export const pingEpic = action$ => action$.pipe(
    ofType('PING'),
    mapTo({ type: 'PONG' })
);

So when I executed the program for the first time I got the following error:

在此输入图像描述

I googled it and found a solution here which says to install rxjs-compat@6 (however it doesn't makes any sense) I installed that too! And then I ran into the following error:

在此输入图像描述 .

I don't know what/where am I doing wrong? Any help would be much appreciated!

Thanks

It should be

import { mapTo } from 'rxjs/operators';

instead of

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM