store
reducer
في محرر الشفرات لإدارة عناصر المهام. قم ADD_TO_DO
كتابة حالة ADD_TO_DO
في المخفض لإلحاق الحالة الجديدة بالحالة. هناك عدة طرق لتحقيق ذلك باستخدام JavaScript قياسي أو ES6. تحقق مما إذا كان يمكنك العثور على طريقة لإرجاع مجموعة جديدة مع العنصر من action.todo
إلى النهاية. todos
في محرر التعليمة البرمجية.
testString: 'assert((function() { const todos = [ "Go to the store", "Clean the house", "Cook dinner", "Learn to code" ]; const initialState = store.getState(); return Array.isArray(initialState) && initialState.join(",") === todos.join(","); })(), "The Redux store should exist and initialize with a state equal to the todos
array in the code editor.");'
- text: addToDo
و immutableReducer
يجب أن يكونا كلاهما.
testString: 'assert(typeof addToDo === "function" && typeof immutableReducer === "function", "addToDo
and immutableReducer
both should be functions.");'
- text: يجب أن يؤدي إرسال إجراء من النوع ADD_TO_DO
على مخزن Redux إلى إضافة عنصر todo
ويجب عدم تحوّل الحالة.
testString: 'assert((function() { const initialState = store.getState(); const isFrozen = DeepFreeze(initialState); store.dispatch(addToDo("__TEST__TO__DO__")); const finalState = store.getState(); const expectedState = [ "Go to the store", "Clean the house", "Cook dinner", "Learn to code", "__TEST__TO__DO__" ]; return( isFrozen && DeepEqual(finalState, expectedState)); })(), "Dispatching an action of type ADD_TO_DO
on the Redux store should add a todo
item and should NOT mutate state.");'
```