UNPKG

redux-form

Version:

A higher order component decorator for forms using Redux and React

58 lines (51 loc) 2.23 kB
import _toPath from 'lodash-es/toPath'; var _extends = Object.assign || 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; }; function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } var deleteInWithPath = function deleteInWithPath(state, first) { for (var _len = arguments.length, rest = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { rest[_key - 2] = arguments[_key]; } if (state === undefined || first === undefined) { return state; } if (rest.length) { if (Array.isArray(state)) { if (first < state.length) { var result = deleteInWithPath.apply(undefined, [state && state[first]].concat(rest)); if (result !== state[first]) { var copy = [].concat(_toConsumableArray(state)); copy[first] = result; return copy; } } return state; } if (first in state) { var _result = deleteInWithPath.apply(undefined, [state && state[first]].concat(rest)); return state[first] === _result ? state : _extends({}, state, _defineProperty({}, first, _result)); } return state; } if (Array.isArray(state)) { if (isNaN(first)) { throw new Error('Cannot delete non-numerical index from an array'); } if (first < state.length) { var _copy = [].concat(_toConsumableArray(state)); _copy.splice(first, 1); return _copy; } return state; } if (first in state) { var _copy2 = _extends({}, state); delete _copy2[first]; return _copy2; } return state; }; var deleteIn = function deleteIn(state, field) { return deleteInWithPath.apply(undefined, [state].concat(_toConsumableArray(_toPath(field)))); }; export default deleteIn;