UNPKG

@angular-redux/store

Version:
17 lines (16 loc) 457 B
/** * Sets a deeply-nested property value from an object, given a 'path' * of property names or array indices. Path elements are created if * not there already. Does not mutate the given object. * * @hidden */ export const setIn = ( obj: Object, [ firstElem, ...restElems ]: (string | number)[], value): Object => ({ ...obj, [firstElem]: restElems.length === 0 ? value : setIn(obj[firstElem] || {}, restElems, value) });