"use strict";

exports.__esModule = true;
exports["default"] = createMergedDefaultStateReducer;
var _reduxAct = require("redux-act");
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); }
//simple wrapper function around createReducer to keep around the default state if type === VECTOR_EDITOR_UPDATE or meta.mergeStateDeep=true
// example:
// defaultState = {features: true, parts: true}
// newState = {features: false}
// stateToUse = {features: false, parts: true}
// instead of
// stateToUse = {features: false}
// these will also be handled differently in the reducer. The __shouldUseMergedState
// attribute will make them not clear unless full overwritten
function createMergedDefaultStateReducer(handlers, defaultState) {
  var reducer = (0, _reduxAct.createReducer)(handlers);
  function enhancedReducer(newState, action) {
    if (newState === void 0) {
      newState = {};
    }
    var stateToUse = action && (action.type === "VECTOR_EDITOR_UPDATE" || action.meta && action.meta.mergeStateDeep) ? _extends({}, defaultState, newState) : newState;
    return reducer(stateToUse, action);
  }
  enhancedReducer.__shouldUseMergedState = true;
  return enhancedReducer;
}
module.exports = exports.default;