ethul / purescript-react-redux

MIT License
15 stars 6 forks source link

Apply middleware API function earlier #9

Closed felixSchl closed 7 years ago

felixSchl commented 7 years ago

This change enables a hack that is employed in a fairly famous library called "redux-saga", where the middleware api is captured during the call to the "applyMiddleware" and subsequently used to dispatch more actions and peek into state.

I use the word "hack" here, because for this to be any useful in a pure language, I have to use unsafePerformEff, which is a hack at best.

Note that this change does neither force this hack on others or encourage it. There should be no observable change to existing codebases.

Applying this function earlier also means that we don't have to redefine the function on every invocation and re-create the middlewareApi object.

Finally, this is consistent with the implementation in the redux source code: https://github.com/reactjs/redux/blob/e2e9648b264224af68add35431898dafe26b0a09/src/applyMiddleware.js

--

I also inlined the actionType as it seems it gets compiled away when building for react native, resulting in "variable actionType not found"

ethul commented 7 years ago

Looks good. Thank you for the PR!