-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
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
compose
is not a normal compose
#632
Comments
I agree, let's fix it somehow. It confused the hell out of me too on one occasion. :-P |
Haha. If you're not open to changing how higher-order stores work (they return a function that takes a "createStore" function), seems like the only option is the change the name. That's the main problem right now: they impose a contract on the composed functions when normally the functions don't even know they are being composed. Even changing the name will cause breakage though, so I dunno. |
I'm open to it as long as we can make dev tools and hot reloading work with some other contract. |
(I don't mind breakage, we'll jump to 2.0 and that'll be it, but we need to make sure new API is better.) |
Here's a simple change that keeps the current interface for middlewares and higher-order stores. Make function compose(...funcs) {
return (...args) => {
const initialValue = funcs[funcs.length - 1].apply(null, args);
const leftFuncs = funcs.slice(0, -1);
return leftFuncs.reduceRight((composed, f) => f(composed),
initialValue);
};
} i.e. it just composes Middlewares would still return a function like compose(
applyMiddleware(middleware1, middleware2),
higherOrderStore,
createDispatcher
) You write: compose(
applyMiddleware(middleware1, middleware2),
higherOrderStore
)(createDispatcher) And in |
I haven't fully read through the other issues, sorry, particularly regarding removing |
Oh it makes sense now. (I assume you meant |
Hah, yes, I am using a simplified version of redux within the devtools until we can make things immutable... |
What about relying on an external |
Yes. |
Fixed by #669. |
Fixed in 2.0. |
Just ran into this... good to see it's already been fixed! |
It would seem that we still don't have the ability to seed our sequence with multiple arguments. Is this expected?
|
I'm happy to accept a PR fixing this. |
Test browser const store = createStore(reducers, {}, compose(
applyMiddleware(ReduxThunk),
window.devToolsExtension ? window.devToolsExtension() : undefined
)); replace with lodash |
You can't pass undefined. Pass a dummy function instead: const store = createStore(reducers, {}, reduceRight(
applyMiddleware(ReduxThunk),
window.devToolsExtension ? window.devToolsExtension() : f => f
)) Or, if you like lodash, you can pass |
Maybe we should accept a PR that removes falsy values. |
compose
is a function that normally doesn't eagerly evaluate it's arguments, but returns a new function that, when called, does the right-to-left evaluation.It's easy if the composition returns a function that takes a single argument (I think this is the proper mathematical composition):
But usually we want to seed the application with multiple args, but it's just a little more code:
This changes the pattern of wrapping
createStore
though. One option would be to rename this toeagerCompose
or something. Not sure if you all are interested in fixing this, but it is somewhat confusing that acts different than most (all?) othercompose
functions.The text was updated successfully, but these errors were encountered: