/
githubmirror
/
immutable-js
Обзор
Документация
Войти
/
githubmirror
/
immutable-js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v5.1.0
src/functional/setIn.ts
28 строк
888 B
Julien Deniau
Migrate functional files to TS (#2063)
23 мар 2025, 00:38
Не верифицирован
23 мар 2025, 00:38
70826e6
Код
Авторство
О чём код?
import { updateIn, type PossibleCollection } from './updateIn'; import { NOT_SET } from '../TrieUtils'; import type { KeyPath } from '../../type-definitions/immutable'; /** * Returns a copy of the collection with the value at the key path set to the * provided value. * * A functional alternative to `collection.setIn(keypath)` which will also * work with plain Objects and Arrays. * * <!-- runkit:activate --> * ```js * import { setIn } from 'immutable'; * * const original = { x: { y: { z: 123 }}} * setIn(original, ['x', 'y', 'z'], 456) // { x: { y: { z: 456 }}} * console.log(original) // { x: { y: { z: 123 }}} * ``` */ export function setIn< K extends PropertyKey, V, TProps extends object, C extends PossibleCollection<K, V, TProps>, >(collection: C, keyPath: KeyPath<K>, value: unknown): C { return updateIn(collection, keyPath, NOT_SET, () => value); }