MCPcopy
hub / github.com/immutable-js/immutable-js / updateIn

Function updateIn

src/functional/updateIn.ts:98–127  ·  view source on GitHub ↗
(
  collection: C,
  keyPath: KeyPath<K>,
  notSetValue: NSV | UpdaterFunction<K, C> | undefined,
  updater?: UpdaterFunctionWithNSV<K, C, NSV>
)

Source from the content-addressed store, hash-verified

96): { [key: PropertyKey]: V };
97
98export function updateIn<
99 K,
100 V,
101 TProps extends object,
102 C extends PossibleCollection<K, V, TProps>,
103 NSV,
104>(
105 collection: C,
106 keyPath: KeyPath<K>,
107 notSetValue: NSV | UpdaterFunction<K, C> | undefined,
108 updater?: UpdaterFunctionWithNSV<K, C, NSV>
109): C {
110 if (!updater) {
111 // handle the fact that `notSetValue` is optional here, in that case `updater` is the updater function
112 // @ts-expect-error updater is a function here
113 updater = notSetValue as UpdaterFunction<K, C>;
114 notSetValue = undefined;
115 }
116 const updatedValue = updateInDeeply(
117 isImmutable(collection),
118 // @ts-expect-error type issues with Record and mixed types
119 collection,
120 coerceKeyPath(keyPath),
121 0,
122 notSetValue,
123 updater
124 );
125 // @ts-expect-error mixed return type
126 return updatedValue === NOT_SET ? notSetValue : updatedValue;
127}
128
129function updateInDeeply<
130 K,

Callers 3

updateFunction · 0.90
removeInFunction · 0.90
setInFunction · 0.90

Calls 3

isImmutableFunction · 0.90
updateInDeeplyFunction · 0.85
coerceKeyPathFunction · 0.85

Tested by

no test coverage detected