本文介绍了如果指定了多个类型和有效负载选项,为什么Redux Promise会返回未解决的promise?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难搞清楚为什么会发生这种情况,但基本上Redux Promise对我来说很好,同时返回的内容如下:

I'm having tough time figuring out why this is happening, but essentially Redux Promise was working fine for me while returning something like:

    return {
      type: STORY_ACTIONS.STORY_SPOTIFY_REQUEST,
      payload: request
    }

但是,我现在需要传递其他信息,如此

However, I now need to pass another information with it like so

    return {
     order: 0, // New field
     type: STORY_ACTIONS.STORY_SPOTIFY_REQUEST,
     payload: request
    }

这导致未解决的承诺而不是数据。我尝试将 order 重命名为 position index 。 ..仍然没有。

This results in an unresolved promise instead of data. I tried renaming order to something like position or index... still nothing.

推荐答案

你应该使用 meta 字段,这是Redux Promise所要求的。 Redux Promise使用Flux标准操作(FSA)来验证操作:

You should use the meta field, which is required by Redux Promise. Redux Promise uses Flux Standard Actions (FSA), which validates the action with this code:

import isPlainObject from 'lodash.isplainobject';

const validKeys = [
  'type',
  'payload',
  'error',
  'meta'
];

function isValidKey(key) {
  return validKeys.indexOf(key) > -1;
}

export function isFSA(action) {
  return (
    isPlainObject(action) &&
    typeof action.type !== 'undefined' &&
    Object.keys(action).every(isValidKey)
  );
}

export function isError(action) {
  return action.error === true;
}

如您所见,有效密钥只有四个保留字。所以你应该将order属性添加到'payload'或者更改为'meta'。

As you can see, there are only four reserved words for valid keys. So you should add the order property to the 'payload' or maybe 'meta' instead.

这篇关于如果指定了多个类型和有效负载选项,为什么Redux Promise会返回未解决的promise?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 00:08