-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Accept stores as an object of prop key to store #31
Conversation
This makes `stores` and `actions` symmetric and lets us specify custom prop names easily. `container` decorator now takes a second argument `transformProps`, which is a function that is used to transform the state and actions props before passing them to the component. It defaults to `({ state, actions }) => { ...state, ...actions }`
Neat! Gonna test this tomorrow morning! |
LGTM. Maybe replacing |
@ooflorent: Maybe we could replace those invariants altogether, with stricter propTypes? static propTypes = {
children: PropTypes.func.isRequired,
actions: PropTypes.objectOf(PropTypes.func).isRequired,
stores: PropTypes.objectOf(PropTypes.func).isRequired
} We would not get a custom error message, but I think it would still be pretty obvious what's wrong, |
@fson I haven't thought about that. Seems to be a viable option. Let's see Dan's opinion. |
stores.every(s => typeof s === 'function'), | ||
'"stores" must be an array of functions. Did you misspell an import?' | ||
isPlainObject(stores) && | ||
Object.keys(stores).every(key => typeof stores[key] === 'function'), |
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.
Addind:
import every from 'lodash/collection/every';
import isFunction from 'lodash/lang/isFunction';
and changing the test to:
isPlainObject(stores) && every(stores, isFunction)
Would make code more readable.
I'd rather keep the invariants. Prop types are cool but out code will crash if you supply something else. The actual error will be more noticeable than propTypes warning and you might struggle longer than you have to. |
Although I sure don't mind stricter propTypes. Just want to also have invariants instead of weird crashes if user doesn't notice the warning. |
This is awesome. Thanks to everybody for a thoughtful discussion. |
Accept stores as an object of prop key to store
This makes
stores
andactions
symmetric and lets us specify customprop names easily.
container
decorator now takes a second argumenttransformProps
,which is a function that is used to transform the state and actions
props before passing them to the component. It defaults to
({ state, actions }) => ({ ...state, ...actions })
I removed some nesting from the states of
counterStore
andtodoStore
examples, because it didn't seem necessary after this change and made prop passing simpler.Fixes #22.