Javascript Redux saga:[…效果]已被弃用,取而代之的是所有([…效果]),请更新您的代码

Javascript Redux saga:[…效果]已被弃用,取而代之的是所有([…效果]),请更新您的代码,javascript,reactjs,redux-saga,Javascript,Reactjs,Redux Saga,我已经将redux saga升级到了最新的0.15.x版本,并且我已经解决了很多关于[…effects]的反对意见,这些意见都被反对,支持所有([…effects]),请更新您的代码 现在只剩下一个弃用,我已经在代码的这一部分中识别了它。有人能看一下下面的代码并指出它是如何触发弃用的吗 我已尝试按照更改日志中的说明进行操作: all effect-并行效果的显式效果,这正是我们通过接受产生的数组所支持的,因此后者现在被弃用,取而代之的是这种显式性,它很好地映射到Promise.all API。请

我已经将redux saga升级到了最新的0.15.x版本,并且我已经解决了很多关于
[…effects]的反对意见,这些意见都被反对,支持所有([…effects]),请更新您的代码

现在只剩下一个弃用,我已经在代码的这一部分中识别了它。有人能看一下下面的代码并指出它是如何触发弃用的吗

我已尝试按照更改日志中的说明进行操作:

all effect-并行效果的显式效果,这正是我们通过接受产生的数组所支持的,因此后者现在被弃用,取而代之的是这种显式性,它很好地映射到Promise.all API。请从现在开始使用此功能

以下是相关代码:

import { call, put, race, take, takeEvery } from 'redux-saga/effects';
import {
  BATCH_START,
  BATCH_SUCCESS,
  BATCH_FAIL,
  SUB_BATCH_START,
  SUB_BATCH_SUCCESS,
  SUB_BATCH_FAIL
} from 'redux/modules/batch/constants';

/*
  This method is required to prevent additional takes.
*/
export function* takeFirstOccurrence(fn) {
  const res = yield take(fn);
  return res;
}

export const takeSuccess = (c) => (b) => b.type === `${c.type}_SUCCESS` && b.batchId === c.batchId;
export const takeFail = (c) => (b) => b.type === `${c.type}_FAIL` && b.batchId === c.batchId;

export function* batchRequest(action, results = {}) {
  const { batchId, actions } = action;
  try {
    const racer = {};
    const takes = [];
    const keysToSuccess = [];

    // Actions must be array
    for (let i = 0; i < actions.length; i++) {
      let c = actions[i];

      if (Array.isArray(c)) {
        const currentBatchId = `${batchId}.${i}`;
        yield put({ type: SUB_BATCH_START, batchId: currentBatchId });
        const res = yield call(batchRequest, { actions: c, batchId: currentBatchId }, results);
        // if the subbatch return object has an error property then everything has gone to shit. Fail the batch/sub-batch. Pass the object up the chain, so the fail reaches the root batch
        if (res.error) {
          results = {
            ...results,
            error: res.error
          };
          // An error has occurred, so hop out of the loop so the parent batch can fail immediately
          // ...or not, for now, since later batches may contain required error logic.
          // i = actions.length;
        } else {
          // update results such that the next array to be called with call(batchRequest...) gets the new results to pass to it's child actions.
          results = {
            ...results,
            ...res
          };
        }
      } else {
        // The batcher expects an object for each action, with one key, the name to associate with the success or error of the action
        const key = Object.keys(c)[0];
        c = c[key];
        // The single property can be either an action object, or a function that returns an action object. If it is a function, it is passed the current results object
        if (typeof c === 'function') {
          c = c(results);
        }
        if (c) {
          c.batchId = `${batchId}.${key}`;
          if (/.*_REQUEST$/.test(c.type)) {
            racer[key] = take(takeFail(c));
            takes.push(takeFirstOccurrence(takeSuccess(c)));
            keysToSuccess.push(key);
          }
          if (c.type) yield put(c);
        }
      }
    }
    // if the "takes" array has no entries then, by definition, the requests are all synchronous and must succeed. There is no return data, so send empty obj with empty success key
    let returnObj = {};
    // if "takes" has entries then the batch/sub-batch contains at least 1 asynchronous action
    if (takes.length > 0) {
      const { success, ...errors } = yield race({
        success: takes,
        ...racer
      });
      // if any of the errors wins the race, then the success property is undefined. Return obj with error property, it will fail the batch/sub-batch.
      if (!success) {
        returnObj = { error: errors };
      } else {
        // else transfer the success array into an object, mapping them in order to the keysToSuccess array constructed eariler
        const successAsKeys = {};
        success.forEach((s, i) => {
          successAsKeys[keysToSuccess[i]] = s;
        });
        returnObj = successAsKeys;
      }
    }
    results = {
      ...results,
      ...returnObj
    };
    // either we reach this point because there are no takes and the batch must succeed, or we exited a loop of arrays, and need to check if there is an error on the results added during that
    if (results.error) {
      yield put({ type: batchId.indexOf('.') === -1 ? BATCH_FAIL : SUB_BATCH_FAIL, batchId, data: results });
    } else {
      yield put({ type: batchId.indexOf('.') === -1 ? BATCH_SUCCESS : SUB_BATCH_SUCCESS, batchId, data: results });
    }
    return results;
  } catch (error) {
    console.log(error);
  }
}

export default function batchListener() {
  return function* actionListener() {
    return yield takeEvery(action => action.type === BATCH_START && action.batchId, batchRequest);
  };
}
import{call,put,race,take,takeEvery}来自'redux saga/effects';
进口{
批量启动,
成功,
批处理失败,
子批次启动,
子批次成功,
子批次失败
}来自“redux/modules/batch/constants”;
/*
需要此方法以防止额外的拍摄。
*/
导出函数*takeFirstOccurrence(fn){
const res=收益率(fn);
返回res;
}
导出const takeSuccess=(c)=>(b)=>b.type==`${c.type}\u SUCCESS`&&b.batchId==c.batchId;
导出常量takeFail=(c)=>(b)=>b.type==`${c.type}\u FAIL`&&b.batchId===c.batchId;
导出函数*batchRequest(操作,结果={}){
常量{batchId,actions}=action;
试一试{
constrracer={};
常量takes=[];
常量keystucture=[];
//操作必须是数组
for(设i=0;i{
successskeys[keystucture[i]]=s;
});
returnObj=成功的;
}
}
结果={
…结果,
…返回OBJ
};
//要么我们到达这一点是因为没有获取并且批处理必须成功,要么我们退出了一个数组循环,并且需要检查在此期间添加的结果是否有错误
if(results.error){
产量投入({type:batchId.indexOf('.')==-1?批次失败:子批次失败,批次ID,数据:结果});
}否则{
产量投入({type:batchId.indexOf('.')==-1?批次成功:子批次成功,批次ID,数据:结果});
}
返回结果;
}捕获(错误){
console.log(错误);
}
}
导出默认函数batchListener(){
返回函数*actionListener(){
返回yield takeEvery(action=>action.type==BATCH\u START&&action.batchId,batchRequest);
};
}

我认为这部分代码可能是其背后的原因:

const { success, ...errors } = yield race({
    success: takes,
    ...racer
});
获取
这是一个数组。如果
all(takes)
修复了它,请尝试