ethul / purescript-react-redux

MIT License
15 stars 6 forks source link

Permit effects in middleware staging #13

Open natefaubion opened 6 years ago

natefaubion commented 6 years ago

I'd like to request changing the type of Middleware from:

newtype Middleware eff state action a b =
  Middleware (MiddlewareAPI eff state action -> Dispatch eff action a -> Dispatch eff action b)

To something like

newtype Middleware eff state action a b =
  Middleware (MiddlewareAPI eff state action -> Eff eff (Dispatch eff action a -> Dispatch eff action b))

Note the intermediate Eff. This is important for doing staged initialization of middlewares. That is, the middleware relies on having the MiddlewareAPI before it can be initialized. In JS, the effects are pervasive so this would just be implicit and expected, and is how Redux internally initializes them. Otherwise in JS, there'd be no use for currying it.

I think technically it should be something like:

newtype Middleware eff state action a b =
  Middleware (MiddlewareAPI eff state action -> Eff eff (Dispatch eff action a -> Eff eff (Dispatch eff action b)))

But I haven't come across a use for the second Eff wrapping.

ethul commented 6 years ago

I like your proposal. Makes sense. If you are interested in opening up a PR for this change, it would definitely be welcome. I can also make the update if you prefer. Thanks!