all files / src/redux/reducers/ auth.js

53.57% Statements 15/28
52.94% Branches 9/17
66.67% Functions 2/3
68.42% Lines 13/19
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 43 44 45 46 47 48 49 50 51 52 53 54                          66× 66×   66×                                                 65×      
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.initialState = undefined;
exports.default = authReducer;
 
var _user = require('../actions/user');
 
var Actions = _interopRequireWildcard(_user);
 
function _interopRequireWildcard(obj) { Eif (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
 
var initialState = exports.initialState = {
  pending: false,
  user: null,
  userMap: {}
};
 
function authReducer() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
  var action = arguments[1];
 
  switch (action.type) {
    case Actions.LOGGED_IN:
      {
        return Object.assign({}, state, { user: action.user });
      }
 
    case Actions.AUTH_PENDING:
      {
        return Object.assign({}, state, { pending: action.pending });
      }
 
    case Actions.LOGOUT:
      {
        return initialState;
      }
 
    case Actions.GET_USERS:
      {
        var users = {};
        action.users.forEach(function (u) {
          users[u._id] = u;
        });
        return Object.assign({}, state, { userMap: users });
      }
 
    default:
      return state;
  }
}