state
不变性的一些细节,但首先,这里是对迄今为止所学到的所有内容的回顾。 incAction
和decAction
操作创建者, decAction
counterReducer()
, INCREMENT
和DECREMENT
操作类型,最后定义Redux store
。一旦完成,您应该能够发送INCREMENT
或DECREMENT
操作来增加或减少store
保存的状态。祝你好运第一个Redux应用程序! incAction
应返回type
等于INCREMENT
值的动作对象
testString: 'assert(incAction().type ===INCREMENT, "The action creator incAction
should return an action object with type
equal to the value of INCREMENT
");'
- text: 动作创建者decAction
应与返回动作对象type
等于的值DECREMENT
testString: 'assert(decAction().type === DECREMENT, "The action creator decAction
should return an action object with type
equal to the value of DECREMENT
");'
- text: Redux存储应该以0 state
初始化。
testString: 'assert(store.getState() === 0, "The Redux store should initialize with a state
of 0.");'
- text: 在Redux存储上调度incAction
应该将state
增加1。
testString: 'assert((function() { const initialState = store.getState(); store.dispatch(incAction()); const incState = store.getState(); return initialState + 1 === incState })(), "Dispatching incAction
on the Redux store should increment the state
by 1.");'
- text: 在Redux存储上调度decAction
应该将state
减1。
testString: 'assert((function() { const initialState = store.getState(); store.dispatch(decAction()); const decState = store.getState(); return initialState - 1 === decState })(), "Dispatching decAction
on the Redux store should decrement the state
by 1.");'
- text: counterReducer
应该是一个函数
testString: 'assert(typeof counterReducer === "function", "counterReducer
should be a function");'
```