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

46.03% Statements 29/63
45.83% Branches 11/24
42.86% Functions 3/7
48% Lines 24/50
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120                                        68× 68×   68×                                                                                                                                                 65×      
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.folderInitialState = exports.initialState = undefined;
exports.default = fsReducer;
 
var _fs = require('../actions/fs');
 
var Actions = _interopRequireWildcard(_fs);
 
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; } }
 
function _defineProperty(obj, key, value) { Iif (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
 
var initialState = exports.initialState = {
  folderMapById: {},
  itemMapById: {},
  selection: []
};
 
var folderInitialState = exports.folderInitialState = {
  open: false,
  folder: null,
  folderChildren: [],
  itemChildren: []
};
 
function fsReducer() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
  var action = arguments[1];
 
  switch (action.type) {
    case Actions.UPDATE_FOLDER:
      {
        var id = action.id,
            folder = action.folder;
 
        var newFolderContainer = Object.assign({}, folderInitialState, state.folderMapById[id], { folder: folder });
        var folderMapById = Object.assign({}, state.folderMapById, _defineProperty({}, id, newFolderContainer));
        return Object.assign({}, state, { folderMapById: folderMapById });
      }
 
    case Actions.UPDATE_ITEMS:
      {
        var newItemMap = Object.assign({}, state.itemMapById);
        action.items.forEach(function (el) {
          newItemMap[el._id] = el;
        });
        return Object.assign({}, state, { itemMapById: newItemMap });
      }
 
    case Actions.CHILDREN_ITEMS:
      {
        var _id = action.id,
            children = action.children;
 
 
        var itemMapById = Object.assign({}, state.itemMapById);
        children.forEach(function (item) {
          itemMapById[item._id] = item;
        });
 
        var itemChildren = children.map(function (item) {
          return item._id;
        });
 
        var _folderMapById = Object.assign({}, state.folderMapById);
        _folderMapById[_id] = Object.assign({}, folderInitialState, state.folderMapById[_id], { itemChildren: itemChildren });
        return Object.assign({}, state, { itemMapById: itemMapById, folderMapById: _folderMapById });
      }
 
    case Actions.CHILDREN_FOLDERS:
      {
        var _id2 = action.id,
            _children = action.children;
 
        var folderChildren = _children.map(function (item) {
          return item._id;
        });
        var _folderMapById2 = Object.assign({}, state.folderMapById);
        _folderMapById2[_id2] = Object.assign({}, folderInitialState, state.folderMapById[_id2], { folderChildren: folderChildren });
        return Object.assign({}, state, { folderMapById: _folderMapById2 });
      }
 
    case Actions.TOGGLE_OPEN_FOLDER:
      {
        var _id3 = action.folderId;
        var _folderMapById3 = Object.assign({}, state.folderMapById);
        var folderObject = Object.assign({}, state.folderMapById[_id3]);
        folderObject.open = !folderObject.open;
        _folderMapById3[_id3] = folderObject;
 
        return Object.assign({}, state, { folderMapById: _folderMapById3 });
      }
 
    case Actions.TOGGLE_FILE_SELECTION:
      {
        var fileId = action.fileId;
        var selection = [].concat(state.selection);
        if (selection.indexOf(fileId) !== -1) {
          selection.splice(selection.indexOf(fileId), 1);
        } else {
          selection.push(fileId);
        }
 
        return Object.assign({}, state, { selection: selection });
      }
 
    case Actions.CLEAR_FILE_SELECTION:
      {
        return Object.assign({}, state, { selection: [] });
      }
 
    default:
      return state;
  }
}