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

54.84% Statements 17/31
56.25% Branches 9/16
66.67% Functions 2/3
68.18% Lines 15/22
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                      66× 66×   66×                                           65×      
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.simInitialState = undefined;
exports.default = simulationsReducer;
 
var _projects = require('../actions/projects');
 
var Actions = _interopRequireWildcard(_projects);
 
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 simInitialState = exports.simInitialState = {
  mapById: {}
};
 
function simulationsReducer() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : simInitialState;
  var action = arguments[1];
 
  switch (action.type) {
    case Actions.REMOVE_SIMULATION:
      {
        var mapById = Object.assign({}, state.mapById);
        delete mapById[action.simulation._id];
        return Object.assign({}, state, { mapById: mapById });
      }
 
    case Actions.UPDATE_SIMULATION:
      {
        var _mapById = Object.assign({}, state.mapById);
        _mapById[action.simulation._id] = action.simulation;
        return Object.assign({}, state, { mapById: _mapById });
      }
 
    case Actions.UPDATE_PROJECT_SIMULATIONS:
      {
        var _mapById2 = Object.assign({}, state.mapById);
        action.simulations.forEach(function (simulation) {
          _mapById2[simulation._id] = simulation;
        });
        return Object.assign({}, state, { mapById: _mapById2 });
      }
 
    default:
      return state;
  }
}