UNPKG

redux-form

Version:

A higher order component decorator for forms using Redux and React

33 lines (29 loc) 983 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _immutable = require('immutable'); exports.default = function () { var list = arguments.length <= 0 || arguments[0] === undefined ? _immutable.List.isList(list) || (0, _immutable.List)() : arguments[0]; var index = arguments[1]; var removeNum = arguments[2]; var value = arguments[3]; if (index < list.count()) { if (value === undefined && !removeNum) { // inserting undefined // first insert null and then re-set it to undefined return list.splice(index, 0, null).set(index, undefined); } if (value != null) { return list.splice(index, removeNum, value); // removing and adding } else { return list.splice(index, removeNum); // removing } } if (removeNum) { // trying to remove non-existant item: return original array return list; } // trying to add outside of range: just set value return list.set(index, value); };