* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
3.3 KiB
3.3 KiB
id, title, challengeType, isRequired, videoUrl, localeTitle
id | title | challengeType | isRequired | videoUrl | localeTitle |
---|---|---|---|---|---|
5a24c314108439a4d4036157 | Write a Counter with Redux | 6 | false | 用Redux写一个计数器 |
Description
state
不变性的一些细节,但首先,这里是对迄今为止所学到的所有内容的回顾。 Instructions
incAction
和decAction
操作创建者, decAction
counterReducer()
, INCREMENT
和DECREMENT
操作类型,最后定义Redux store
。一旦完成,您应该能够发送INCREMENT
或DECREMENT
操作来增加或减少store
保存的状态。祝你好运第一个Redux应用程序! Tests
tests:
- text: 动作创建者<code>incAction</code>应返回<code>type</code>等于<code>INCREMENT</code>值的动作对象
testString: assert(incAction().type ===INCREMENT);
- text: 动作创建者<code>decAction</code>应与返回动作对象<code>type</code>等于的值<code>DECREMENT</code>
testString: assert(decAction().type === DECREMENT);
- text: Redux存储应该以0 <code>state</code>初始化。
testString: assert(store.getState() === 0);
- text: 在Redux存储上调度<code>incAction</code>应该将<code>state</code>增加1。
testString: assert((function() { const initialState = store.getState(); store.dispatch(incAction()); const incState = store.getState(); return initialState + 1 === incState })());
- text: 在Redux存储上调度<code>decAction</code>应该将<code>state</code>减1。
testString: assert((function() { const initialState = store.getState(); store.dispatch(decAction()); const decState = store.getState(); return initialState - 1 === decState })());
- text: <code>counterReducer</code>应该是一个函数
testString: assert(typeof counterReducer === 'function');
Challenge Seed
const INCREMENT = null; // define a constant for increment action types
const DECREMENT = null; // define a constant for decrement action types
const counterReducer = null; // define the counter reducer which will increment or decrement the state based on the action it receives
const incAction = null; // define an action creator for incrementing
const decAction = null; // define an action creator for decrementing
const store = null; // define the Redux store here, passing in your reducers
Solution
// solution required