Procházet zdrojové kódy

promise_reducer switch refactor

pocu46 před 3 roky
rodič
revize
ae35ba9f04
1 změnil soubory, kde provedl 29 přidání a 12 odebrání
  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) => {