-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Allow for passing of action creators through Connector and @connect decorator
#86
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
Changes from all commits
3e0eee9
eb52e83
f000e0c
134eeb3
f5c570b
19070b7
3a00ff9
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 |
|---|---|---|
|
|
@@ -4,9 +4,9 @@ redux | |
| [](https://travis-ci.org/gaearon/redux) | ||
| [](https://www.npmjs.com/package/redux) | ||
|
|
||
| An experiment in fully hot-reloadable Flux. | ||
| An experiment in fully hot-reloadable Flux. | ||
|
|
||
| **The API might change any day.** | ||
| **The API might change any day.** | ||
| _**Don't use in production just yet.**_ | ||
|
|
||
| ## Why another Flux framework? | ||
|
|
@@ -140,10 +140,8 @@ export default class Counter { | |
|
|
||
| ```js | ||
| // The smart component may observe stores using `<Connector />`, | ||
| // and bind actions to the dispatcher with `bindActionCreators`. | ||
|
|
||
| import React from 'react'; | ||
| import { bindActionCreators } from 'redux'; | ||
| import { Connector } from 'redux/react'; | ||
| import Counter from '../components/Counter'; | ||
| import * as CounterActions from '../actions/CounterActions'; | ||
|
|
@@ -158,11 +156,13 @@ function select(state) { | |
| export default class CounterApp { | ||
| render() { | ||
| return ( | ||
| <Connector select={select}> | ||
| {({ counter, dispatch }) => | ||
| // Passing an object of action creators here automatically binds them | ||
| // with Redux's dispatcher and passes them to the child function | ||
| // (so they can be passed as props to child components) | ||
| <Connector select={select} actionCreators={CounterActions}> | ||
| {({ counter, actions }) => | ||
|
Contributor
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. Shouldn't this be
Contributor
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. Quick question, isn't
Contributor
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 think if we call it “stores” people will be tempted to pass actual Store functions there.
Contributor
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 see your point, I just think that
Contributor
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. Maybe something with a more contextual name (e.g.: |
||
| /* Yes this is child as a function. */ | ||
| <Counter counter={counter} | ||
| {...bindActionCreators(CounterActions, dispatch)} /> | ||
| <Counter counter={counter} {...actions} /> | ||
| } | ||
| </Connector> | ||
| ); | ||
|
|
@@ -176,22 +176,23 @@ The `@connect` decorator lets you create smart components less verbosely: | |
|
|
||
| ```js | ||
| import React from 'react'; | ||
| import { bindActionCreators } from 'redux'; | ||
| import { connect } from 'redux/react'; | ||
| import Counter from '../components/Counter'; | ||
| import * as CounterActions from '../actions/CounterActions'; | ||
|
|
||
| // Pass an object of action creators you want to pass | ||
| // as the `actions` prop to your component as the (optional) | ||
| // second parameter of @connect | ||
| @connect(state => ({ | ||
| counter: state.counter | ||
| })) | ||
| }), CounterActions) | ||
| export default class CounterApp { | ||
| render() { | ||
| const { counter, dispatch } = this.props; | ||
| // Instead of `bindActionCreators`, you may also pass `dispatch` as a prop | ||
| // to your component and call `dispatch(CounterActions.increment())` | ||
| const { counter, actions, dispatch } = this.props; | ||
| // Instead of passing action creators as a parameter to @connect to autobind them, you may also | ||
| // pass `dispatch` as a prop to your component and call `dispatch(CounterActions.increment())` | ||
| return ( | ||
| <Counter counter={counter} | ||
| {...bindActionCreators(CounterActions, dispatch)} /> | ||
| <Counter counter={counter} {...actions} /> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,16 @@ | ||
| import React from 'react'; | ||
| import { bindActionCreators } from 'redux'; | ||
| import { connect } from 'redux/react'; | ||
| import Counter from '../components/Counter'; | ||
| import * as CounterActions from '../actions/CounterActions'; | ||
|
|
||
| @connect(state => ({ | ||
| counter: state.counter | ||
| })) | ||
| }), CounterActions) | ||
| export default class CounterApp { | ||
| render() { | ||
| const { counter, dispatch } = this.props; | ||
| const { counter, actions } = this.props; | ||
| return ( | ||
| <Counter counter={counter} | ||
| {...bindActionCreators(CounterActions, dispatch)} /> | ||
| <Counter counter={counter} {...actions} /> | ||
| ); | ||
| } | ||
| } |
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.
Whitespace is significant in Markdown :-). I have these double spaces for a reason here. Can you please change them back?