From 98baf5cffc3e0c690fe9e1755d860490f29031da Mon Sep 17 00:00:00 2001 From: mudrz Date: Tue, 10 Oct 2017 21:39:20 +0300 Subject: [PATCH 1/3] Add dispatch shorthand example to documentation --- docs/api.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/api.md b/docs/api.md index f188a4fb1..5392b4055 100644 --- a/docs/api.md +++ b/docs/api.md @@ -218,6 +218,26 @@ function mapDispatchToProps(dispatch) { export default connect(mapStateToProps, mapDispatchToProps)(TodoApp) ``` +##### Inject `todos` and a specific action creator (`addTodo` and `deleteTodo`) - shorthand +```js +import { addTodo, deleteTodo } from './actionCreators' + +function mapStateToProps(state) { + return { todos: state.todos } +} + +// shorthand object, a map between the names of the callback props +// that we want to inject and the action creator functions that create the corresponding actions +// in this case the action creator `addTodo` will be mapped and dispatched through property `addTodo2` +// it is a good practice to keep names 1:1 to make mapping even easier - `deleteTodo` +const mapDispatchToProps = { + addTodo2: addTodo, + deleteTodo +} + +export default connect(mapStateToProps, mapDispatchToProps)(TodoApp) +``` + ##### Inject `todos`, todoActionCreators as `todoActions`, and counterActionCreators as `counterActions` ```js From 0df38af5864ba45f146d0642d4c8d2698a78e731 Mon Sep 17 00:00:00 2001 From: mudrz Date: Tue, 10 Oct 2017 22:12:21 +0300 Subject: [PATCH 2/3] Update api.md removed rename, simplified comment --- docs/api.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/api.md b/docs/api.md index 5392b4055..e5757ac60 100644 --- a/docs/api.md +++ b/docs/api.md @@ -226,12 +226,9 @@ function mapStateToProps(state) { return { todos: state.todos } } -// shorthand object, a map between the names of the callback props -// that we want to inject and the action creator functions that create the corresponding actions -// in this case the action creator `addTodo` will be mapped and dispatched through property `addTodo2` -// it is a good practice to keep names 1:1 to make mapping even easier - `deleteTodo` +// shorthand object, a map between the names of the callback props and action creators const mapDispatchToProps = { - addTodo2: addTodo, + addTodo, deleteTodo } From 9036363b191e77fdec403587bd741ca2d95515e6 Mon Sep 17 00:00:00 2001 From: Tim Dorr Date: Tue, 10 Oct 2017 16:45:25 -0400 Subject: [PATCH 3/3] Cleanups --- docs/api.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/api.md b/docs/api.md index e5757ac60..c646499c6 100644 --- a/docs/api.md +++ b/docs/api.md @@ -218,7 +218,7 @@ function mapDispatchToProps(dispatch) { export default connect(mapStateToProps, mapDispatchToProps)(TodoApp) ``` -##### Inject `todos` and a specific action creator (`addTodo` and `deleteTodo`) - shorthand +##### Inject `todos` and specific action creators (`addTodo` and `deleteTodo`) with shorthand syntax ```js import { addTodo, deleteTodo } from './actionCreators' @@ -226,7 +226,6 @@ function mapStateToProps(state) { return { todos: state.todos } } -// shorthand object, a map between the names of the callback props and action creators const mapDispatchToProps = { addTodo, deleteTodo