Apply middleware API function earlier #9
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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"