Closed wachunei closed 4 years ago
Hi @wachunei! These are great questions.
Yes, this is intended behavior for the alias
middleware. The only thing we wanted aliases to be used for is "swapping" one action for another, and allowing other middleware down the chain to respond to this new action.
To your point, most people that I've worked with have used alias
es with redux thunk, so there is not as large a need to pass it to additional middleware. That said, there are members who use aliases in a long chain of custom middleware, and we've designed the current middleware to support both use cases.
Hi @tshaddix!
I see! Here I'm actually manually composing alias and a redux-thunk equivalent.
I should decouple them and compose them as middlewares, and wherever I was using my custom middleware thunks (action, { dispatch, getState } ) => {}
turn it into a regular thunk (action) => (dispatch, getState) => {}
and let the middlewares handle them.
Thank you for your answer! Going to close this.
@wachunei No problem! Exactly.
That said, it really is up to however you want to do it - that's why we built the aliases as a middleware you can include or not include. The custom middleware you made makes a lot of sense for the problem you are trying to solve!
I'm taking a look at the
alias
middleware source code:and I have a question: why do we push down the middleware chain the return of the alias? This would mean every alias must resolve to an action.
Is this intended?
My approach
Heavily inspired by redux-thunk (which is kinda the same idea) I came up with this alias middleware:
Main differences are: