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.
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"