TypeError:Object(...)(...)。flatMap不是函数

时间:2020-04-02 03:55:54

标签: reactjs redux rxjs

请帮助我为什么会出现此错误?

enter image description here

import { FETCHING_DATA } from '../constants'
import { getDataSuccess, getDataFailure } from './actions'
import getPeople from '../api'

import { from, Observable, of} from 'rxjs';
// import 'rxjs'
// import { Observable } from 'rxjs/Observable';
import { mergeMap } from 'rxjs/operators';
import { ofType } from 'redux-observable';

// const fetchUserEpic = action$ =>
//   action$.ofType(FETCHING_DATA)
//     .mergeMap(action =>
//       Observable.fromPromise(getPeople())
//         .map(response => getDataSuccess(response))
//         .catch(error => Observable.of(getDataFailure(error)))
//       )

const fetchUserEpic = action$ =>
  action$.pipe(  //fixed
    ofType(FETCHING_DATA),
    mergeMap(action => {
      return from(getPeople())
        .flatMap(payload => [
          {
            type: 'SIGNUP_CONCIERGE_SUCCESS',
            payload
          }
        ])
        .catch(error =>
          of({
            type: 'SIGNUP_CONCIERGE_ERROR',
            payload: { error }
          })
        );
    })
  );

export default fetchUserEpic

1 个答案:

答案 0 :(得分:2)

这是来自redux-observable的示例

  csv_data="D:\Desktop\DS\DSDA\Assignment\"
 for a in range(60):
     #add the '.csv' here
     csv_data = csv_data + str(a)+'.csv'
csv_data = DataFrameDict[a].to_csv(csv_data, index = False, header=True)`
#what is this line for?
csv_data = ""

这里是采用的解决方案

import { ajax } from 'rxjs/ajax';

const fetchUserEpic = action$ => action$.pipe(
  ofType(FETCH_USER),
  mergeMap(action => ajax.getJSON(`/api/users/${action.payload}`).pipe(
    map(response => fetchUserFulfilled(response)),
    catchError(error => of({
      type: FETCH_USER_REJECTED,
      payload: error.xhr.response,
      error: true
    }))
  ))
);