Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React redux observable:在epic中进行连续API调用_Reactjs_Redux_Rxjs_Redux Observable - Fatal编程技术网

Reactjs React redux observable:在epic中进行连续API调用

Reactjs React redux observable:在epic中进行连续API调用,reactjs,redux,rxjs,redux-observable,Reactjs,Redux,Rxjs,Redux Observable,我正在尝试使用redux observable进行顺序API调用。第一次API调用的结果数据应用于进行下一次调用。解释了如何在Angular中使用rxjs,但我无法传授知识 我已经编写了两部史诗,我想把它们结合起来: const createList: Epic = (action$) => action$.pipe( /* * Post a new empty list */ ofType(CREATE_LIST), switchMap(({ payload }) =

我正在尝试使用redux observable进行顺序API调用。第一次API调用的结果数据应用于进行下一次调用。解释了如何在Angular中使用rxjs,但我无法传授知识

我已经编写了两部史诗,我想把它们结合起来:

const createList: Epic = (action$) => action$.pipe(
  /*
  * Post a new empty list
  */
  ofType(CREATE_LIST),
  switchMap(({ payload }) => {
    const [postData, config] = prepareListRequest(payload);
    return from(axios.post<IAPIList>('http://127.0.0.1:8000/lists/', postData, config))
      .pipe(
        map(({ data }) => createListSuccessAction(data)),
        catchError((err) => of(ErrorAction(err))),
      );
  }),
);

const createItem: Epic = (action$) => action$.pipe(
  /*
  * Post a new item. Here the listID is in the payload. 
  */
  ofType(CREATE_ITEM),
  switchMap(({ payload }) => {
    const [postData, config] = prepareItemRequest(payload);
    return from(axios.post<IAPIItem>('http://127.0.0.1:8000/items/', postData, config,))
      .pipe(
        map(({ data }) => createItemSuccessAction(data)),
        catchError((err) => of(ErrorAction(err))),
    );
  }),
);

提前感谢您的时间:)

利用RxJS将承诺自动转换为可观测值的能力,并使用
mergeMap
+异步函数

const createPopulatedList=(action$)=>action$.pipe(
ofType(创建填充列表),
合并映射(异步({list,item})=>{
const{id}=wait firstAPICall(列表);
返回所有(项目,id);
})
);

利用RxJS将承诺自动转换为可观测值的能力,并使用
mergeMap
+异步函数

const createPopulatedList=(action$)=>action$.pipe(
ofType(创建填充列表),
合并映射(异步({list,item})=>{
const{id}=wait firstAPICall(列表);
返回所有(项目,id);
})
);
const createPopulatedList: Epic = (action$) => action$.pipe(
  ofType(CREATE_POPULATED_LIST),
  res = firstAPICall(payload.list)
  secondAPICall(payload.item, res.id)
);