File size: 859 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {RECEIVE_CURRENT_USER,RECEIVE_USER, LOGOUT_CURRENT_USER }
 from '../actions/session_actions';
import merge from 'lodash/merge';
const _nullSession = {
    id: null
};

const SessionReducer = (state = _nullSession, action) => {
  Object.freeze(state);


  switch (action.type) {
    case RECEIVE_CURRENT_USER:
    let newCState;
    if(action.currentUser.id === undefined){
      newCState= {
        id: Object.keys(action.currentUser)
    };
    }else{
        newCState= {
          id: action.currentUser.id
      };
   }
   return merge({}, state, newCState );
   //  case RECEIVE_USER:
   //  const newState= {
   //      id: action.user.id
   //  };
   //
   // return merge({}, state, newState );

    case LOGOUT_CURRENT_USER:
      return merge({},state,_nullSession);

    default:
      return state;

  }
};

export default SessionReducer;