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

Method delete

packages/mobx/src/types/observablemap.ts:168–214  ·  view source on GitHub ↗
(key: K)

Source from the content-addressed store, hash-verified

166 }
167
168 delete(key: K): boolean {
169 checkIfStateModificationsAreAllowed(this.keysAtom_)
170 if (hasInterceptors(this)) {
171 const change = interceptChange<IMapWillChange<K, V>>(this, {
172 type: DELETE,
173 object: this,
174 name: key
175 })
176 if (!change) {
177 return false
178 }
179 }
180 if (this.has_(key)) {
181 const notifySpy = isSpyEnabled()
182 const notify = hasListeners(this)
183 const change: IMapDidChange<K, V> | null =
184 notify || notifySpy
185 ? {
186 observableKind: "map",
187 debugObjectName: this.name_,
188 type: DELETE,
189 object: this,
190 oldValue: (<any>this.data_.get(key)).value_,
191 name: key
192 }
193 : null
194
195 if (__DEV__ && notifySpy) {
196 spyReportStart(change! as PureSpyEvent)
197 } // TODO fix type
198 transaction(() => {
199 this.keysAtom_.reportChanged()
200 this.hasMap_.get(key)?.setNewValue_(false)
201 const observable = this.data_.get(key)!
202 observable.setNewValue_(undefined as any)
203 this.data_.delete(key)
204 })
205 if (notify) {
206 notifyListeners(this, change)
207 }
208 if (__DEV__ && notifySpy) {
209 spyReportEnd()
210 }
211 return true
212 }
213 return false
214 }
215
216 private updateValue_(key: K, newValue: V | undefined) {
217 const observable = this.data_.get(key)!

Callers 2

clearMethod · 0.95
replaceMethod · 0.95

Calls 14

has_Method · 0.95
hasInterceptorsFunction · 0.85
interceptChangeFunction · 0.85
isSpyEnabledFunction · 0.85
hasListenersFunction · 0.85
spyReportStartFunction · 0.85
notifyListenersFunction · 0.85
spyReportEndFunction · 0.85
setNewValue_Method · 0.80
getMethod · 0.65
reportChangedMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected