MCPcopy
hub / github.com/mobxjs/mobx / addValue_

Method addValue_

packages/mobx/src/types/observablemap.ts:247–283  ·  view source on GitHub ↗
(key: K, newValue: V)

Source from the content-addressed store, hash-verified

245 }
246
247 private addValue_(key: K, newValue: V) {
248 checkIfStateModificationsAreAllowed(this.keysAtom_)
249 transaction(() => {
250 const observable = new ObservableValue(
251 newValue,
252 this.enhancer_,
253 __DEV__ ? `${this.name_}.${stringifyKey(key)}` : "ObservableMap.key",
254 false
255 )
256 this.data_.set(key, observable)
257 newValue = (observable as any).value_ // value might have been changed
258 this.hasMap_.get(key)?.setNewValue_(true)
259 this.keysAtom_.reportChanged()
260 })
261 const notifySpy = isSpyEnabled()
262 const notify = hasListeners(this)
263 const change: IMapDidChange<K, V> | null =
264 notify || notifySpy
265 ? {
266 observableKind: "map",
267 debugObjectName: this.name_,
268 type: ADD,
269 object: this,
270 name: key,
271 newValue
272 }
273 : null
274 if (__DEV__ && notifySpy) {
275 spyReportStart(change! as PureSpyEvent)
276 } // TODO fix type
277 if (notify) {
278 notifyListeners(this, change)
279 }
280 if (__DEV__ && notifySpy) {
281 spyReportEnd()
282 }
283 }
284
285 get(key: K): V | undefined {
286 if (this.has(key)) {

Callers 1

setMethod · 0.95

Calls 12

stringifyKeyFunction · 0.85
isSpyEnabledFunction · 0.85
hasListenersFunction · 0.85
spyReportStartFunction · 0.85
notifyListenersFunction · 0.85
spyReportEndFunction · 0.85
setNewValue_Method · 0.80
setMethod · 0.65
getMethod · 0.65
reportChangedMethod · 0.65
transactionFunction · 0.50

Tested by

no test coverage detected