function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import omit from "lodash/omit";
import uuid from "shortid";

// ------------------------------------
// Reducer
// ------------------------------------
export default function upsertDeleteActionGenerator(upsertAction, deleteAction) {
  var _ref;
  return _ref = {}, _ref[upsertAction] = function (state, payload) {
    var _extends2;
    var idToUse = payload.id || uuid();
    return _extends({}, state, (_extends2 = {}, _extends2[idToUse] = _extends({}, state[idToUse] || {}, payload, {
      id: idToUse
    }), _extends2));
  }, _ref[deleteAction] = function (state, payload) {
    var ids;
    if (Array.isArray(payload)) {
      ids = payload.map(function (val) {
        return val.id || val;
      });
    } else {
      ids = [payload.id || payload];
    }
    return omit(state, ids);
  }, _ref;
}