( state: object, key: string, value: any, destroyArrays: boolean = false )
| 160 | }; |
| 161 | |
| 162 | const setIn: SetIn = ( |
| 163 | state: object, |
| 164 | key: string, |
| 165 | value: any, |
| 166 | destroyArrays: boolean = false |
| 167 | ): object => { |
| 168 | if (state === undefined || state === null) { |
| 169 | throw new Error(`Cannot call setIn() with ${String(state)} state`); |
| 170 | } |
| 171 | if (key === undefined || key === null) { |
| 172 | throw new Error(`Cannot call setIn() with ${String(key)} key`); |
| 173 | } |
| 174 | // Recursive function needs to accept and return State, but public API should |
| 175 | // only deal with Objects |
| 176 | return setInRecursor( |
| 177 | state, |
| 178 | 0, |
| 179 | toPath(key), |
| 180 | value, |
| 181 | destroyArrays |
| 182 | ) as object; |
| 183 | }; |
| 184 | |
| 185 | export default setIn; |
no test coverage detected
searching dependent graphs…