lelandrichardson / redux-pack

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

Pass the whole action into the handlers #66

Closed icambron closed 2 years ago

icambron commented 6 years ago

One problem I'm having is that I can't pass any extra context into the handlers because the rest of the action is stripped away. For example, let's say I have a search:

export const search = keyword => ({
  type: "SEARCH",
  keyword,
  promise: makeSomeAPICall(keyword)
});

I'm putting keyword in the actual action because I want access to it at the start phase of my handler (e.g. to show some UI about it). But as far as I can tell, I don't have access to properties like that in my reducer, because pack isn't doing either of these: a) passing the original action's fields into dispatch or b) passing the original action's fields into the event hooks.

jorbascrumps commented 6 years ago

@icambron You can pass arbitrary data with the meta field:

export const search = keyword => ({
  type: "SEARCH",
  promise: makeSomeAPICall(keyword),
  meta: {
    keyword
  }
});

You can then grab the action (containing the meta data) as the second argument in your handler.

icambron commented 6 years ago

@iamchristopher I ended up doing just that after reading more code. It didn't strike me that that it was intended for that, though. Is it?