Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitddb0e55

Browse files
committed
tutorial fixes
1 parent41a3cd3 commitddb0e55

File tree

10 files changed

+26
-62
lines changed

10 files changed

+26
-62
lines changed

‎README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,3 @@ const nextPokemon = state.pokemon.map(p => {
101101
pokemon: nextPokemon
102102
};
103103
```
104-
105-
#####Combine Reducers
106-
107-
Create modular, composable reducers with`combineReducers`.

‎coderoad.json

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -231,36 +231,17 @@
231231
"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 ```",
232232
"tasks": [
233233
{
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`.",
235235
"tests": [
236236
"05/01"
237237
],
238238
"actions": [
239239
"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"
252240
],
253241
"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"
255243
]
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+
},
264245
{
265246
"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.",
266247
"tests": [

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"testSuffix":".js"
2121
},
2222
"dependencies": {
23-
"mocha-coderoad":"0.9.1"
23+
"mocha-coderoad":"0.10.0"
2424
}
2525
}

‎tutorial/02/01.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ chai.use(spies);
66
letspy=chai.spy.on(console,'log');
77

88
constindexJs=require('BASE/src/index.js');
9+
conststore=indexJs.__get__('store');
910

1011
describe('01 Redux',()=>{
1112

‎tutorial/02/03.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
conststore=indexJs.__get__('store');
2-
31
describe('03 store',()=>{
42

53
it('isn\'t defined. `const store`',()=>{

‎tutorial/02/04.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe('04 log store',()=>{
22

33
it('isn\'t logged to the console. `console.log(store)`',()=>{
4-
expect(spy).to.have.been.called();
4+
expect(spy).to.have.been.called.with(store);
55
});
66

77
});

‎tutorial/02/06.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
describe('06loginitialState',()=>{
1+
describe('06 initialState',()=>{
22

3-
it('isn\'t logged to the console.',()=>{
3+
constinitialState=indexJs.__get__('initialState');
44

5-
constinitialState={
6-
pokemon:[{
7-
id:1,
8-
name:'Luvdisc',
9-
description:'This heart-shaped POKéMON earned its name by swimming after loving couples it spotted in the ocean’s waves.',
10-
votes:3
11-
},{
12-
id:2,
13-
name:'Trubbish',
14-
description:'Wanting more garbage, they follow people who litter. They always belch poison gas.',
15-
votes:2
16-
},{
17-
id:3,
18-
name:'Stunfisk',
19-
description:'Its skin is very hard, so it is unhurt even if stepped on by sumo wrestlers. It smiles when transmitting electricity.',
20-
votes:0
21-
}]
22-
};
5+
it('should be above the store',()=>{
6+
expect(initialState).to.not.be.undefined;
7+
expect(store.getState()).to.deep.equal(initialState);
8+
});
239

10+
it('isn\'t logged to the console.',()=>{
2411
expect(spy).to.have.been.called.with(initialState);
2512
});
2613

‎tutorial/05/index.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ const nextPokemon = state.pokemon.map(p => {
1616
};
1717
```
1818

19-
+ Return a new list of Pokemon after incrementing "votes" of the pokemon with the matching "id"
19+
+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"
2020
@test('05/01')
2121
@action(open('src/index.js'))
22+
@hint('Try this:`case VOTE_UP: const pokemon = state.pokemon.map(p => {`')
23+
@hint('If the pokemon.id matches the payload.id, increase the votes by one')
24+
@hint('Don't forget to return the new state')
25+
@hint('Try returning`return { pokemon };`')
2226

2327
+ 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.
2428
@test('05/02')
29+
@hint('Try this:`const initialState = Object.freeze({ ... })`')
2530

2631
+ 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`
2732
@test('05/03')
28-
@hint('return`Object.assign({}, { pokemon: nextPokemon });`')
33+
@hint('return`Object.assign({},state,{ pokemon: nextPokemon });`')
2934

3035
@onPageComplete('Now that you have an idea of how reducers work. Next we can look at how to create multiple, modular reducers.')

‎tutorial/06/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
##Combine Reducers
22
Create modular, composable reducers with`combineReducers`.
33

4-
5-
64
+ 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.
75
@test('06/01')
86
@action(open('src/index.js'))

‎tutorial/07/05.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
describe('05 import',()=>{
22

3-
// read index.js path for regexing for import and moved files
4-
constindexJsPath=resolve(process.env.DIR,'index.js');
5-
constindexJsFinal=readFileSync(indexJsPath,'utf8');
6-
73
it('`voteUp` from "./pokemon" in "index.js"',()=>{
8-
constregex=/import\s?\{\s?(.+,?\s?|voteUp,?\s?|sortByPopularity,?\s?)+\s?\}\s?from\s?[\"\']\.?\/?pokemon(\/index(\.js)?)?[\"\'];?/m;
9-
expect(indexJsFinal).to.match(regex);
4+
constvoteUp=indexJs.__get__('voteUp');
5+
expect(voteUp).to.not.be.undefined;
6+
expect(typeofvoteUp).to.equal('function');
107
});
118

129
it('`default as pokemon` from "./pokemon" in "index.js"',()=>{
13-
constregex=/import\s?\{\s?(.+,?\s?|defaultaspokemon,?\s?|sortByPopularity,?\s?)+\s?\}\s?from\s?[\"\']\.?\/?pokemon(\/index(\.js)?)?[\"\'];?/m;
14-
expect(indexJsFinal).to.match(regex);
10+
constpokemon=indexJs.__get__('pokemon');
11+
expect(pokemon).to.not.be.undefined;
12+
expect(typeofpokemon).to.equal('function');
1513
});
1614

1715
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp