|
259 | 259 | "05/03" |
260 | 260 | ], |
261 | 261 | "hints": [ |
| 262 | + "Try this: `case VOTE_UP: const pokemon = state.pokemon.map(...)`", |
262 | 263 | "return `Object.assign({}, state, { pokemon: nextPokemon });`" |
263 | 264 | ] |
264 | 265 | } |
|
270 | 271 | "description": "Create modular, composable reducers with `combineReducers`.\n\nExplanation here.", |
271 | 272 | "tasks": [ |
272 | 273 | { |
273 | | - "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.", |
| 274 | + "description": "create a new `const reducers` and set it equal to \"reducer\". Pass \"reducers\" into your store for now, instead of \"reducer\". If this seems convoluted it is because we're trying not to break the app.", |
274 | 275 | "tests": [ |
275 | 276 | "06/01" |
276 | 277 | ], |
|
283 | 284 | ] |
284 | 285 | }, |
285 | 286 | { |
286 | | - "description": "We're going to create more than one reducer. They can't all be called \"reducer\", so rename your original reducer \"pokemon\". Make sure to set reducers equal to the new name as well.", |
| 287 | + "description": "We're going to create more than one reducer. They can't all be called \"reducer\", so rename your original reducer \"pokemon\". Make sure to set `reducers` equal to the new name as well.", |
287 | 288 | "tests": [ |
288 | 289 | "06/02" |
289 | 290 | ], |
|
295 | 296 | ] |
296 | 297 | }, |
297 | 298 | { |
298 | | - "description": "import `combineReducers` from redux", |
| 299 | + "description": "When we use `combineReducers` we will be able to define the initial state inside of each reducer. To keep things working, we'll have to do this step by step. Copy the \"pokemon\" key from `initialState` and give it its own variable called \"defaultPokemon\". It should be an array with three pokemon.", |
299 | 300 | "tests": [ |
300 | 301 | "06/03" |
301 | 302 | ], |
302 | 303 | "hints": [ |
303 | | - "Try this: `import { combineReducers } from 'redux';`" |
| 304 | + "Like this: `const defaultPokemon = [{ ... }, { ... }, { ... }]`" |
304 | 305 | ] |
305 | 306 | }, |
306 | 307 | { |
307 | | - "description": "combineReducers(), and pass in your reducer ({ pokemon })", |
| 308 | + "description": "Set your pokemon reducer first param, state, to equal \"pokemon\", and give it a default value of `defaultPokemon` using ES6 default params.", |
308 | 309 | "tests": [ |
309 | 310 | "06/04" |
310 | 311 | ], |
311 | 312 | "hints": [ |
312 | | - "Try this: `const reducers = combineReducers({pokemon});`" |
| 313 | + "Default params work like this: `fn(param1 = defaultParam, param2)`", |
| 314 | + "Like this: `const pokemon = (pokemon = defaultPokemon, action) => {`" |
313 | 315 | ] |
314 | 316 | }, |
315 | 317 | { |
316 | | - "description": "We're going to shake things up now to make our reducers more composable. Set the initial state inside of your `createStore` to simply be an empty object (`{}`)", |
| 318 | + "description": "Fix references to \"state\" inside your reducer to match the passed in value \"pokemon\"", |
317 | 319 | "tests": [ |
318 | 320 | "06/05" |
| 321 | + ], |
| 322 | + "hints": [ |
| 323 | + "Change three references to \"pokemon\" in your pokemon reducer", |
| 324 | + "First: 'const pokemon = (pokemon = defaultPokemon, action) => {`", |
| 325 | + "Second: `const nextPokemon = pokemon.map(...)`", |
| 326 | + "Third: `default: return pokemon;`" |
319 | 327 | ] |
320 | 328 | }, |
321 | 329 | { |
322 | | - "description": "Thanks to `combineReducers` we can now define the initial state inside of each reducer. Get rid of \"initialState\", but keep the \"pokemon\" key and call it \"defaultPokemon\". It should be an array with three pokemon. Finally, pass the `defaultPokemon` as the default state in the pokemon reducer. You can use ES6 default params.", |
| 330 | + "description": "Our initial state is now handled by `defaultPokemon`. Set the initial state inside of your `createStore` to simply be an empty object (`{}`).", |
323 | 331 | "tests": [ |
324 | 332 | "06/06" |
325 | 333 | ], |
326 | 334 | "hints": [ |
327 | | - "Like this: `const defaultPokemon = [{ id: 1, name: 'Luvdisc', ...`", |
328 | | - "Default params work like this: `fn(param1 = defaultParam, param2)`", |
329 | | - "Like this: `const pokemon = (state = defaultPokemon, action) => {`" |
| 335 | + "Try this: `const store = createStore(reducers, {});`" |
330 | 336 | ] |
331 | 337 | }, |
332 | 338 | { |
333 | | - "description": "We no longer pass the entire \"state\" inside of our reducers, only the slice of our state the reducer needs to know. Rename all references to \"state\" inside of your \"pokemon\" reducer to what it really is now: \"pokemon\".", |
| 339 | + "description": "import `combineReducers` from redux", |
334 | 340 | "tests": [ |
335 | 341 | "06/07" |
336 | 342 | ], |
337 | 343 | "hints": [ |
338 | | - "Change three references to \"pokemon\" in your pokemon reducer", |
339 | | - "Third: `default: return pokemon;`" |
| 344 | + "Try this: `import { combineReducers } from 'redux';`" |
| 345 | + ] |
| 346 | + }, |
| 347 | + { |
| 348 | + "description": "`reducers` should now call `combineReducers` instead and call `pokemon`. `combineReducers` takes an object with keys of each reducer.", |
| 349 | + "tests": [ |
| 350 | + "06/08" |
| 351 | + ], |
| 352 | + "hints": [ |
| 353 | + "Try this: `const reducers = combineReducers({pokemon});`" |
340 | 354 | ] |
341 | 355 | } |
342 | 356 | ], |
|
0 commit comments