UNPKG

redux-form

Version:

A higher order component decorator for forms using Redux and React

27 lines (25 loc) 869 B
import { List } from 'immutable'; export default (function () { var list = arguments.length <= 0 || arguments[0] === undefined ? List.isList(list) || 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); });