|
486 | 486 | }, |
487 | 487 | { |
488 | 488 | "title": "Second Action", |
489 | | - "description": "Creating a \"SORT_BY_POPULARITY\" action.\n\n```js\nfunction sortByVotes(a, b) {\n switch(true) {\n case a.votes < b.votes:\n return 1;\n case a.votes > b.votes:\n return -1;\n default:\n return 0;\n }\n }\n```\n\nSort pokemon by votes", |
| 489 | + "description": "Creating a \"SORT_BY_POPULARITY\" action.\n\n```js\nfunction sortByVotes(a, b) {\n switch(true) {\n case a.votes < b.votes: return 1;\n case a.votes > b.votes: return -1;\n default: return 0;\n }\n }\n```\n\nSort pokemon by votes", |
490 | 490 | "tasks": [ |
491 | 491 | { |
492 | | - "description": "create an action type for 'SORT_BY_POPULARITY'", |
| 492 | + "description": "in \"src/pokemon/index.js\", create an action type for 'SORT_BY_POPULARITY'", |
493 | 493 | "tests": [ |
494 | 494 | "09/01" |
495 | 495 | ], |
496 | 496 | "actions": [ |
497 | 497 | "open('src/pokemon/index.js')" |
| 498 | + ], |
| 499 | + "hints": [ |
| 500 | + "Try this: `const SORT_BY_POPULARITY = 'SORT_BY_POPULARITY';`" |
498 | 501 | ] |
499 | 502 | }, |
500 | 503 | { |
501 | | - "description": "create an action creator called 'sortByPopularity'", |
| 504 | + "description": "create the action creator called 'sortByPopularity' and export it", |
502 | 505 | "tests": [ |
503 | 506 | "09/02" |
| 507 | + ], |
| 508 | + "hints": [ |
| 509 | + "It should be a function that returns `{ type: SORT_BY_POPULARITY }`", |
| 510 | + "Try this: `const sortByPopularity = () => ({ ... })`", |
| 511 | + "It should be exported using `export`" |
504 | 512 | ] |
505 | 513 | }, |
506 | 514 | { |
507 | | - "description": "dispatch a `sortByPopularity` action after the two voteUp dispatches", |
| 515 | + "description": "import `sortByPopularity` in \"src/index.js\".", |
508 | 516 | "tests": [ |
509 | 517 | "09/03" |
| 518 | + ], |
| 519 | + "hints": [ |
| 520 | + "Try this: `import { sortByPopularity } from './pokemon';`" |
510 | 521 | ] |
511 | 522 | }, |
512 | 523 | { |
513 | | - "description": "add a `SORT_BY_POPULARITY` case that returns `pokemon.sort();`", |
| 524 | + "description": "in \"src/index.js\", dispatch a `sortByPopularity` action at the bottom of the page", |
514 | 525 | "tests": [ |
515 | 526 | "09/04" |
| 527 | + ], |
| 528 | + "hints": [ |
| 529 | + "use `store.dispatch(actionCreator)`", |
| 530 | + "Try this: `store.dispatch(sortByPopularity())`" |
516 | 531 | ] |
517 | 532 | }, |
518 | 533 | { |
519 | | - "description": "create a sortByVotes function and pass it into the pokemon.sort function", |
| 534 | + "description": "add a `SORT_BY_POPULARITY` case that returns `pokemon.sort();`", |
520 | 535 | "tests": [ |
521 | 536 | "09/05" |
| 537 | + ], |
| 538 | + "hints": [ |
| 539 | + "Try this: `case SORT_BY_POPULARITY: return pokemon.sort()`" |
522 | 540 | ] |
523 | 541 | }, |
524 | 542 | { |
525 | | - "description": "Make a `sortByKey` function, which is more reusable, by wrapping it in a function that takes a key", |
| 543 | + "description": "use the `sortByVotes` function and pass it into the `pokemon.sort` function. Sorting function return 1, -1, or 0 depending on where the index of b should be arranged around a.", |
526 | 544 | "tests": [ |
527 | 545 | "09/06" |
| 546 | + ], |
| 547 | + "hints": [ |
| 548 | + "Try this: `case SORT_BY_POPULARITY: return pokemon.sort(sortByVotes)`" |
| 549 | + ], |
| 550 | + "actions": [ |
| 551 | + "insert('\nfunction sortByVotes(a, b) {\n switch(true) {\n case a.votes > b.votes:\n return 1;\n case a.votes < b.votes:\n return -1;\n default: return 0;\n }\n}\n\n')" |
528 | 552 | ] |
529 | 553 | }, |
530 | 554 | { |
531 | | - "description": "You've just created a **thunk** - a function that returns a function. Pass your function into the pokemon.sort() method and give it the key of 'votes'", |
| 555 | + "description": "Use the `sortByKey` function, which is more reusable. It should take a param of \"key\" and return a function similar to `sortByVotes`, but sorting on the \"key\" param.", |
532 | 556 | "tests": [ |
533 | 557 | "09/07" |
| 558 | + ], |
| 559 | + "actions": [ |
| 560 | + "insert('\nfunction sortByKey(key) {\n return function(a, b) {\n\n // sorting cases here\n\n }\n}\n')" |
| 561 | + ] |
| 562 | + }, |
| 563 | + { |
| 564 | + "description": "You've just created a **thunk** - a function that returns a function. Pass your function into the `pokemon.sort()` method and give it the key of 'votes'", |
| 565 | + "tests": [ |
| 566 | + "09/08" |
| 567 | + ], |
| 568 | + "hints": [ |
| 569 | + "Try this: `sortByKey('votes')`", |
| 570 | + "Try this: pokemon.sort(sortByKey('votes'))" |
534 | 571 | ] |
535 | 572 | } |
536 | 573 | ], |
|
0 commit comments