authenticated . تحتاج أيضًا إلى منشئي إجراءات ينشئون إجراءات تتوافق مع تسجيل دخول المستخدم وخروج المستخدم ، بالإضافة إلى كائنات الإجراءات نفسها. reducer للتعامل مع إجراءات التوثيق المتعددة. استخدم عبارة switch JavaScript في reducer للرد على أحداث إجراء مختلفة. هذا هو نمط قياسي في كتابة مخفضات Redux. يجب أن يقوم بيان التبديل action.type وإرجاع حالة المصادقة المناسبة. ملاحظة: في هذه المرحلة ، لا تقلق بشأن ثبات النظام ، لأنها صغيرة وبسيطة في هذا المثال. لكل إجراء ، يمكنك إرجاع كائن جديد - على سبيل المثال ، {authenticated: true} . لا تنس أيضًا كتابة حالة default في كشف التبديل الخاص بك تقوم بإرجاع state الحالية. هذا أمر مهم لأنه بمجرد أن يحتوي تطبيقك على مخفضات متعددة ، يتم تشغيلها في أي وقت يتم فيه إرسال إجراء ، حتى عندما لا يكون الإجراء مرتبطًا بمخفض المخفِّض هذا. في مثل هذه الحالة ، تحتاج إلى التأكد من إرجاع state الحالية. loginUser استدعاء الدالة loginUser إرجاع كائن له خاصية كتابة معينة إلى السلسلة LOGIN .
testString: 'assert(loginUser().type === "LOGIN", "Calling the function loginUser should return an object with type property set to the string LOGIN.");'
- text: ''
testString: 'assert(logoutUser().type === "LOGOUT", "Calling the function logoutUser should return an object with type property set to the string LOGOUT.");'
- text: ''
testString: 'assert(store.getState().authenticated === false, "The store should be initialized with an object with an authenticated property set to false.");'
- text: ''
testString: 'assert((function() { const initialState = store.getState(); store.dispatch(loginUser()); const afterLogin = store.getState(); return initialState.authenticated === false && afterLogin.authenticated === true })(), "Dispatching loginUser should update the authenticated property in the store state to true.");'
- text: ''
testString: 'assert((function() { store.dispatch(loginUser()); const loggedIn = store.getState(); store.dispatch(logoutUser()); const afterLogout = store.getState(); return loggedIn.authenticated === true && afterLogout.authenticated === false })(), "Dispatching logoutUser should update the authenticated property in the store state to false.");'
- text: ''
testString: 'getUserInput => assert( getUserInput("index").toString().includes("switch") && getUserInput("index").toString().includes("case") && getUserInput("index").toString().includes("default"), "The authReducer function should handle multiple action types with a switch statement.");'
```