Skip to content

Commit 1f4c867

Browse files
committed
Merge branch 'ISSUE-22'
05_get-state.js Object Spread Fix Object Spread is an ES7 featurev + details its use
2 parents 9047ac7 + e8afb2a commit 1f4c867

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ npm-debug.log
33
.DS_Store
44
dist
55
nested-dispatch.js
6+
test.js

05_get-state.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,17 @@ console.log('redux state after initialization:', store_3.getState())
9292
// 2) When using a switch, NEVER forget to have a "default: return state" because
9393
// if you don't, you'll end up having your reducer return undefined (hence loosing your state).
9494
// 3) Notice how we returned a new state made by merging current state with { message: action.value },
95-
// all that thanks to this awesome es6 notation: { ...state, message: action.value }
95+
// all that thanks to this awesome ES7 notation (Object Spread): { ...state, message: action.value }
96+
// 4) Note also that this ES7 Object Spread notation suits our example because it's doing a shallow
97+
// copy of { message: action.value } over our state (meaning that first level property of state
98+
// are completely overwritten - by opposition to gracefully merged - by first level property of
99+
// { message: action.value }). But if we had a more complex / nested data structure, you may choose
100+
// to handle your state's updates very differently:
101+
// - using Immutable.js (https://facebook.github.io/immutable-js/)
102+
// - using Object.assign (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
103+
// - using manual merge
104+
// - or whatever other strategy that suits your needs and the structure of your state since
105+
// Redux is absolutely NOT opiniated on this (remember, Redux is a state container).
96106

97107
// Now that we're starting to handle actions in our reducer let's speak about having multiple reducers and
98108
// combining them.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This repository contains a step by step tutorial to get a grasp about flux and m
88
The official and very exhaustive Redux documentation is available [here](http://gaearon.github.io/redux/) and should be your number One source of truth regarding Redux. The present tutorial only will offer you an introduction to flux concepts through Redux use but for further or more detailled infos, please refer to the Redux documentation.
99

1010
### Prerequisites
11-
It is required for you to know a bit of ES6 to understand correctly some of the examples given in this repo. Be also aware that this tutorial targets redux 1.0.0.
11+
It is required for you to know a bit of ES6 and ES7 (Object Spread) to understand correctly some of the examples given in this repo. Be also aware that this tutorial targets redux 1.0.0.
1212

1313
### Clone the repository
1414
`git clone https://github.com/happypoulp/redux-tutorial.git`

0 commit comments

Comments
 (0)