-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default function combineReducers(reducers) { | ||
return function(state = {}, action, args) { | ||
return Object.entries(reducers).reduce( | ||
(acc, [name, reducer]) => Object.assign(acc, { | ||
[name]: reducer(state[name], action, args), | ||
}), | ||
state | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import html from "../index"; | ||
|
||
export default function ArchivedTask(text) { | ||
export default function ArchivedTask({task}) { | ||
return html` | ||
<li style="color:#666; text-decoration:line-through"> | ||
${text} | ||
${task} | ||
</li> | ||
`; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import html from "../index"; | ||
import { connect } from "./store"; | ||
|
||
import TextInput from "./TextInput"; | ||
import CharCounter from "./CharCounter"; | ||
|
||
export default function App(idx) { | ||
return html` | ||
${TextInput(idx)} | ||
${TextInput({idx})} | ||
${CharCounter()} | ||
`; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe 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); |
||
// Return a decorated component function. | ||
return (...args) => component(state, ...args); | ||
return (props, ...args) => | ||
component(Object.assign({}, props, selector(state)), ...args); | ||
}, | ||
dispatch(action, ...args) { | ||
state = reducer(state, action, args); | ||
|
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
thensubstate
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.