Skip to content

Apply middleware API function earlier #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2017
Merged

Conversation

felixSchl
Copy link
Contributor

@felixSchl felixSchl commented Aug 22, 2017

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"

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 the "applyMiddleware" and subsequently used to dispatch more
actions and peek into state.

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
It seems to get compiled away when building for react-native
@ethul
Copy link
Owner

ethul commented Aug 28, 2017

Looks good. Thank you for the PR!

@ethul ethul merged commit a4b25b6 into ethul:master Aug 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants