Skip to content

Commit 1432209

Browse files
committed
update step 2
1 parent d9c696d commit 1432209

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

tutorial/02/05.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
describe('05 log store.getState()', () => {
2+
3+
it('isn\'t logged to the console.', () => {
4+
expect(spy).to.have.been.called.with(store.getState());
5+
});
6+
7+
});

tutorial/02/06.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
describe('06 log initialState', () => {
2+
3+
it('isn\'t logged to the console.', () => {
4+
5+
const initialState = {
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+
};
23+
24+
expect(spy).to.have.been.called.with(initialState);
25+
});
26+
27+
});

tutorial/02/index.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,53 @@ The "single source of truth".
55
const store = createStore(reducer, initialState);
66
```
77

8-
+ install Redux. Run `npm install --save redux`.
8+
+ install Redux.
9+
@hint('Run `npm install --save redux`.')
910
@action(open('index.js'))
1011
@test('02/01')
1112

12-
+ import createStore. `import { createStore } from 'redux';`
13+
+ import `createStore` from the redux module.
14+
@hint('Add `import { createStore } from 'redux';`')
1315
@test('02/02')
1416

1517
+ create your first store and call it `store`. Use a simple "reducer" function for now, let's say `state => state`.
18+
@hint('declare your store, `const store`')
19+
@hint('call store with a simple reducer, `const store = createStore(state => state)`')
1620
@test('02/03')
1721

1822
+ log your store to the console and have a look.
1923
@test('02/04')
24+
@hint('`console.log(store)`')
25+
26+
+ log `store.getState()` to the console
27+
@test('02/05')
28+
@hint('`console.log(store.getState())`')
29+
30+
+ move the initial state to the top of the file, and pass it in as a second param your `createStore`
31+
@test('02/06')
32+
@hint('Move `initialState` above your `store`')
33+
@hint('Pass in `initialState` as a second param to `createStore`')
34+
@action(insert(
35+
```
36+
const initialState = {
37+
pokemon: [{
38+
id: 1,
39+
name: 'Luvdisc',
40+
description: 'This heart-shaped POKéMON earned its name by swimming after loving couples it spotted in the ocean’s waves.',
41+
votes: 3
42+
}, {
43+
id: 2,
44+
name: 'Trubbish',
45+
description: 'Wanting more garbage, they follow people who litter. They always belch poison gas.',
46+
votes: 2
47+
}, {
48+
id: 3,
49+
name: 'Stunfisk',
50+
description: 'Its skin is very hard, so it is unhurt even if stepped on by sumo wrestlers. It smiles when transmitting electricity.',
51+
votes: 0
52+
}]
53+
};
54+
```
55+
))
2056

2157
@onPageComplete('As you can see, the store is just an object with various methods like "dispatch" and "getState". Let's see what these methods do in the next step.')

0 commit comments

Comments
 (0)