leoasis / redux-immutable-state-invariant

Redux middleware that detects mutations between and outside redux dispatches. For development use only.
MIT License
937 stars 37 forks source link

Usage with "in-flight", non-serialisable actions. #2

Closed eldh closed 9 years ago

eldh commented 9 years ago

As discussed here, FSA compliant actions can be non-serialisable while they are waiting for a promise to resolve, causing errors when trying to use this lib (JSON.serialize() fails).

I have a small example todo app that uses redux-actions and redux-promises, and I would love to find a way to add redux-immutable-state-invariant to it.

Not sure how to go about doing that though, and I'm not sure my understanding of the problem is correct.

I would guess though that the "isFSA()" and "isSerializable()" methods discussed in the issue mentioned above could be used to filter out actions that should not be checked. But then again, I'm not sure this lib should necessarily know too much about FSA... Perhaps it could be as easy as checking if the payload is a Promise?

Or is it better to find a way to completely avoid non-serialisable actions?

Maybe @acdlite has some input?

leoasis commented 9 years ago

@eldh what's your particular use case? The original idea of this library is to work with plain actions that go directly to the reducer, that is, after all the middlewares have been executed. So you should place this middleware after all the other middlewares that transform your dispatched actions into the final ones that transform the state.

Is there a specific reason you would want this to work with the other intermediate actions?

Having said that, ideally I would love to have the same behavior to print stuff in the console as console.log, where objects and functions and everything gets printed correctly, instead of relying on JSON.stringify. If there's a better way to get an action pretty printed, I'm all for it.

eldh commented 9 years ago

Sorry, it was just me who didn't understand the importance of the order of middleware in this case. Placing it at the end works fine.