-
Notifications
You must be signed in to change notification settings - Fork 28
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
WIP Selectors #22
base: master
Are you sure you want to change the base?
WIP Selectors #22
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give this a closer look in the morning but at first glance this looks good. An example using combineReducers
would be nice but certainly not necessary in this PR.
CHANGELOG.md
Outdated
|
||
You can now pass an optional selector function to `connect`. It will be | ||
passed the `state` and should return an object which will be merged with | ||
the component's `props` using `Object.assign({}, props, substate`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a closing )
Thanks. I'll add an example and tests for |
|
||
You can now pass an optional selector function to `connect`. It will be | ||
passed the `state` and should return an object which will be merged with | ||
the component's `props` using `Object.assign({}, props, substate)`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order of first props
then substate
mimics what Redux does. I've wondered why they implement it this way. substate, props
would allow overriding the props from state which sounds like it could be useful sometimes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely think this makes more sense but I am curious as to what trade off the redux team made when they designed it the other way. There has to be a reason behind it.
Once this is fixed 👍 |
@@ -44,9 +44,10 @@ export function createStore(reducer) { | |||
roots.set(root, component); | |||
render(); | |||
}, | |||
connect(component) { | |||
connect(component, selector = state => state) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a nit / question -- is your preference to keep the selector as the second arg, vs the react-redux style
const ConnectedFoo = connect(state => ({ bar: state.foo.bar }))(Foo);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess (to kinda answer my own question) your way allows connecting to the state without any selectors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which would need to be something like the following in react-redux style,
const ConnectedFoo = connect()(Foo);
Here's a WIP of my proposal to fix #19. I still need to add more tests and fix the failing ones. In the interest of gathering feedback early I'm submitting the PR now.
I split the change into three commits and it might be helpful to review them one by one.