You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"description": "The data transformation\n\n```js\nconst reducer = (state) => {\nconsole.log(state);\n return state;\n};\n```",
8
+
"title": "Pure Functions",
9
+
"description": "Reducers must be pure functions\n\nState is \"read only\".\n\nNotes\n```js\nconst nextPokemon = state.pokemon.map(p => {\n if (id === p.id) {\n p.votes += 1;\n }\nreturn p;\n });\n return {\n pokemon: nextPokemon\n };\n```",
10
10
"tasks": [
11
11
{
12
-
"description": "Extract the `state => state` function in create store, and call in a new function called \"reducer\".",
12
+
"description": "Return a new list of Pokemon after incrementing \"votes\" of the pokemon with the matching \"id\"",
13
13
"tests": [
14
-
"04/01"
15
-
],
16
-
"actions": [
17
-
"open('index.js')"
18
-
]
19
-
},
20
-
{
21
-
"description": "Log the state inside of your reducer. What does it look like?",
22
-
"tests": [
23
-
"04/02"
24
-
],
25
-
"hints": [
26
-
"Add a `console.log` statement inside of your reducer function",
"description": "Pass an action as a second param to the reducer",
32
-
"tests": [
33
-
"04/03"
14
+
"05/01"
34
15
]
35
16
},
36
17
{
37
-
"description": "Dispatch two voteUp actions through the reducer: `store.dispatch(voteUp(2))`. Change your log statement inside of your reducer to look like this: `console.log('state: ', state, 'action: ', action)`",
18
+
"description": "Let's make a test to see that we are truly returning a new state. Wrap your `initialState` object in a `Object.freeze`. Freeze makes an object unchangeable. And yet your reducer should still work.",
38
19
"tests": [
39
-
"04/04"
20
+
"05/02"
40
21
]
41
22
},
42
23
{
43
-
"description": "Create a `switch` statement and pass in `action.type`, the default return should return `state`",
24
+
"description": "What if we were dealing with multiple keys on the state. We'd have to ensure that our changes return a complete new state each time. Use `Object.assign`",
44
25
"tests": [
45
-
"04/05"
46
-
]
47
-
},
48
-
{
49
-
"description": "The `switch` statement should have a `default` case that returns the state",
50
-
"tests": [
51
-
"04/06"
52
-
]
53
-
},
54
-
{
55
-
"description": "add a switch case for `VOTE_UP`. For now, just console.log the `id` of the action passed in and return the default state again.",
Copy file name to clipboardExpand all lines: tutorial/04/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,5 +36,5 @@ const reducer = (state) => {
36
36
+ The `switch` statement should have a `default` case that returns the state
37
37
@test('04/06')
38
38
39
-
+ add a switch case for `VOTE_UP`. For now, just console.log the `id` of the action passed in and return the default state again.
39
+
+ add a switch case for `VOTE_UP`. For now, just console.log the `id` of the action passed in and return the default state again. Tip: destructuring: `const { id } = action.payload;`
+ Return a new list of Pokemon with the pokemon matching the id incrementing its votes by one
19
+
+ Return a new list of Pokemon after incrementing "votes" of the pokemon with the matching "id"
17
20
@test('05/01')
18
21
19
-
20
-
21
-
+ Use Object.assign
22
+
+ Let's make a test to see that we are truly returning a new state. Call `Object.freeze()` on your `initialState`. `freeze` makes an object immutable - meaning the object can not be changed. And yet your reducer should still work, since it returns a new state each call.
22
23
@test('05/02')
24
+
25
+
+ What if we were dealing with multiple keys on the state. We'd have to ensure that our changes return a complete new state each time. Use `Object.assign`
0 commit comments