|
231 | 231 | "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 }\n return p;\n });\n return {\n pokemon: nextPokemon\n };\n ```",
|
232 | 232 | "tasks": [
|
233 | 233 | {
|
234 |
| -"description":"Return a new list of Pokemon after incrementing\"votes\" of the pokemon with the matching\"id\"", |
| 234 | +"description":"Time to make the VOTE_UP action change the state.Return a new list of Pokemon after incrementing\"votes\" of the pokemon with the matching\"id\"\nCreate modular, composable reducers with `combineReducers`.", |
235 | 235 | "tests": [
|
236 | 236 | "05/01"
|
237 | 237 | ],
|
238 | 238 | "actions": [
|
239 | 239 | "open('src/index.js')"
|
240 |
| - ] |
241 |
| - }, |
242 |
| - { |
243 |
| -"description":"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.", |
244 |
| -"tests": [ |
245 |
| -"05/02" |
246 |
| - ] |
247 |
| - }, |
248 |
| - { |
249 |
| -"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`", |
250 |
| -"tests": [ |
251 |
| -"05/03" |
252 | 240 | ],
|
253 | 241 | "hints": [
|
254 |
| -"return`Object.assign({}, { pokemon: nextPokemon });`" |
| 242 | +"'Try this: `case VOTE_UP: const pokemon = state.pokemon.map(p => {`')@hint('If the pokemon.id matches the payload.id, increase the votes by one')\n@hint('Don't forget toreturnthe new state')\n@hint('Try returning `return { pokemon };`')\n\n+ 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.\n@test('05/02')\n@hint('Try this: `const initialState = Object.freeze({ ... })`')\n\n+ 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`\n@test('05/03')\n@hint('return `Object.assign({},state,{ pokemon: nextPokemon });`')\n\n\n## Combine Reducer" |
255 | 243 | ]
|
256 |
| - } |
257 |
| - ], |
258 |
| -"onPageComplete":"Now that you have an idea of how reducers work. Next we can look at how to create multiple, modular reducers." |
259 |
| - }, |
260 |
| - { |
261 |
| -"title":"Combine Reducers", |
262 |
| -"description":"Create modular, composable reducers with `combineReducers`.", |
263 |
| -"tasks": [ |
| 244 | + }, |
264 | 245 | {
|
265 | 246 | "description":"create a new `const reducers` and set it equal to\"reducer\". Pass\"reducers\" into your store for now, instead of\"reducer\". We'll use combineReducers shortly, but let's not break the app yet.",
|
266 | 247 | "tests": [
|
|