lelandrichardson / redux-pack

Sensible promise handling and middleware for redux
MIT License
1.33k stars 60 forks source link

Actions should be FSA-complient #10

Closed ArnaudRinquin closed 7 years ago

ArnaudRinquin commented 7 years ago

While not critical, I think it'd be better if actions were FSA (flux-standard-action) compliant.

Instead of dispatching actions such as:

{
  type: LOAD_FOO,
  promise: Api.getFoo(id),
};

I suggest the actions to be on the form of either:

{
  type: LOAD_FOO,
  payload: Api.getFoo(id),
};

or

{
  type: LOAD_FOO,
  meta: {
    promise: Api.getFoo(id),
  },
};

The changes required on the middleware would be small and back-compatibility could be provided.

ArnaudRinquin commented 7 years ago

As stated in #11, the first option is not possible as the payload data is actually used and transmitted as the start action payload.

Only the second option, having the promise in action.meta.promise is available but the middleware should make sur to not propagate the promise in follow-up actions.

lelandrichardson commented 7 years ago

@ArnaudRinquin thanks for bringing up this issue and even opening up a PR to change it!

I've talked about this with a few people in the past and I don't think I am going to do this. redux-pack is FSA compliant as is, because only FSA-compliant actions get fed to the reducers. This is no different than redux-thunk where you are dispatching a function (which is not FSA compliant), but the function then in turn dispatches other actions.

Since this is a pretty common thing to bring up, perhaps it's a good idea to mention this in the README though.

ArnaudRinquin commented 7 years ago

because only FSA-compliant actions get fed to the reducers

Oh that's a good argument. Fair enough.

it's a good idea to mention this in the README though.

Yep.