Browse Source

promise_reducer switch refactor

pocu46 3 năm trước cách đây
mục cha
commit
ae35ba9f04
1 tập tin đã thay đổi với 29 bổ sung12 xóa
  1. 29 12
      hipstagram/src/Redux/promise_reducer.js

+ 29 - 12
hipstagram/src/Redux/promise_reducer.js

@@ -10,20 +10,37 @@ const RESOLVED = 'RESOLVED';
 const REJECTED = 'REJECTED';
  
 const promiseReducer = (state, action) => {
-    if (action.type === LOGIN || action.type === LOGOUT) {
-        return {}
-    }
-    if (action.type === PROMISE) {
-        return{
-            ...state,
-            [action.name]: {
-                status: action.status, 
-                payload: (action.status === PENDING && state[action.name] && state[action.name].payload) || action.payload, // зачем эта проверка?
-                error: action.error
+//     if (action.type === LOGIN || action.type === LOGOUT) {
+//         return {}
+//     }
+//     if (action.type === PROMISE) {
+//         return{
+//             ...state,
+//             [action.name]: {
+//                 status: action.status, 
+//                 payload: (action.status === PENDING && state[action.name] && state[action.name].payload) || action.payload, // зачем эта проверка?
+//                 error: action.error
+//             }
+//         }
+//     }
+// return state
+    switch(action.type) {
+        case LOGIN:
+            return {};
+        case LOGOUT:
+            return {};
+        case PROMISE:
+            return{
+                ...state,
+                [action.name]: {
+                    status: action.status, 
+                    payload: (action.status === PENDING && state[action.name] && state[action.name].payload) || action.payload, // зачем эта проверка?
+                    error: action.error
+                }
             }
-        }
+        default: 
+            return state;
     }
-return state
 }
 
 const actionPromise = (name, promise) => {