Redux epics返回的操作数组中的“错误:操作必须是普通对象”

Redux epics返回的操作数组中的“错误:操作必须是普通对象”,redux,rxjs,redux-observable,Redux,Rxjs,Redux Observable,对于从epics返回的所有操作集,我们都会得到此错误 这可能是因为史诗是如何在史诗创作者中建立的: 要么映射在这里不正确,要么更可能在史诗中不正确 funcaction调用的一个epic示例,存储: 如果没有方括号,它也可以正常工作,请尝试以下建议: [String(usersActions.updateUser)]: (action, store) => { return authFetch(`${API_ROOT}/user/${get(action, 'payload.i

对于从epics返回的所有操作集,我们都会得到此错误

这可能是因为史诗是如何在史诗创作者中建立的:

要么映射在这里不正确,要么更可能在史诗中不正确

funcaction调用的一个epic示例,存储:

如果没有方括号,它也可以正常工作,请尝试以下建议:

  [String(usersActions.updateUser)]: (action, store) => {
    return authFetch(`${API_ROOT}/user/${get(action, 'payload.id')}`, {
      method: 'put',
      headers: {
       ...
      },
      body: ...,
    })
      .then(resJson => {
        if (resJson['status'] === 200) {
          return [
            appActions.pushNotification('success', USER_UPDATE_SUCCESS),
            appActions.setNextPath(`/users/${get(action, 'payload.id')}`),
          ]
        } else
          return [
            appActions.pushNotification(
              'error',
              USER_UPDATE_FAILED + ': ' + resJson['message']
            ),
          ]
      })
      .catch(() => {
        return [appActions.pushNotification('error', USER_UPDATE_FAILED)]
      })
  },
它会删除错误,但已调度的操作现在是重复的


已经尝试过所有选项,希望这不是一个重复的问题。

您可以在epic末尾添加一个.doaction=>console.logaction,以查看您发出的值以及为什么它们不是动作。e、 如果是一系列动作,那就不正确了。Epics应该只发出带有类型属性的普通旧javascript操作。

您能简化为一个最小的可复制示例吗?我听不懂。你好@jayphelps,谢谢你的帮助。最后,第一部史诗的风格是正确的。我必须添加.flatmap=>e数组实例?e:[e]发送给epics的创建者,并用raw传递动作,否则会多次发送动作。
const epic = (action$, store) => 
   action$.ofType(String(key)).mergeMap(action => func(action, store))
  [String(usersActions.updateUser)]: (action, store) => {
    return authFetch(`${API_ROOT}/user/${get(action, 'payload.id')}`, {
      method: 'put',
      headers: {
       ...
      },
      body: ...,
    })
      .then(resJson => {
        if (resJson['status'] === 200) {
          return [
            appActions.pushNotification('success', USER_UPDATE_SUCCESS),
            appActions.setNextPath(`/users/${get(action, 'payload.id')}`),
          ]
        } else
          return [
            appActions.pushNotification(
              'error',
              USER_UPDATE_FAILED + ': ' + resJson['message']
            ),
          ]
      })
      .catch(() => {
        return [appActions.pushNotification('error', USER_UPDATE_FAILED)]
      })
  },
  [String(usersActions.updateUser)]: (action, store) => {
    return Rx.Observable.fromPromise(
      fetch(`${API_ROOT}/user/${get(action, 'payload.id')}`, {
        method: 'put',
        headers: {},
      }).then(res => res.json())
    )
      .mergeMap(resJson => {
        if (resJson['status'] === 200) {
          return Rx.Observable.concat(
            Rx.Observable.of(
              appActions.pushNotification('success', USER_UPDATE_SUCCESS)
            ),
            Rx.Observable.of(
              appActions.setNextPath(`/users/${get(action, 'payload.id')}`)
            )
          )
        } else return
        Rx.Observable.concat(
          Rx.Observable.of(
            appActions.pushNotification(
              'error',
              USER_UPDATE_FAILED + ': ' + resJson['message']
            )
          )
        )
      })
      .catch(() => {
        Rx.Observable.concat(
          Rx.Observable.of(
            appActions.pushNotification('error', USER_UPDATE_FAILED)
          )
        )
      })
  },