Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Redux Promise return unresolved promise if more than type and payload options are specified?

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
    }

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

like image 691
Ilja Avatar asked Feb 12 '16 11:02

Ilja


1 Answers

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;
}

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.

like image 158
larrydahooster Avatar answered Nov 20 '22 10:11

larrydahooster