mobx 6.3.13 → 6.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +1 -0
  3. package/dist/errors.d.ts +2 -2
  4. package/dist/mobx.cjs.development.js +940 -263
  5. package/dist/mobx.cjs.development.js.map +1 -1
  6. package/dist/mobx.cjs.production.min.js.map +1 -1
  7. package/dist/mobx.esm.development.js +940 -263
  8. package/dist/mobx.esm.development.js.map +1 -1
  9. package/dist/mobx.esm.js +958 -269
  10. package/dist/mobx.esm.js.map +1 -1
  11. package/dist/mobx.esm.production.min.js.map +1 -1
  12. package/dist/mobx.umd.development.js +940 -263
  13. package/dist/mobx.umd.development.js.map +1 -1
  14. package/dist/mobx.umd.production.min.js.map +1 -1
  15. package/dist/types/observablemap.d.ts +2 -2
  16. package/dist/utils/utils.d.ts +1 -1
  17. package/package.json +1 -1
  18. package/src/api/action.ts +8 -3
  19. package/src/api/annotation.ts +1 -2
  20. package/src/api/autorun.ts +22 -8
  21. package/src/api/computed.ts +5 -2
  22. package/src/api/configure.ts +6 -2
  23. package/src/api/extendobservable.ts +11 -5
  24. package/src/api/extras.ts +4 -2
  25. package/src/api/flow.ts +11 -4
  26. package/src/api/intercept-read.ts +4 -2
  27. package/src/api/intercept.ts +5 -2
  28. package/src/api/iscomputed.ts +10 -4
  29. package/src/api/isobservable.ts +10 -4
  30. package/src/api/makeObservable.ts +4 -2
  31. package/src/api/object-api.ts +30 -16
  32. package/src/api/observable.ts +23 -9
  33. package/src/api/observe.ts +4 -2
  34. package/src/api/tojs.ts +7 -3
  35. package/src/api/trace.ts +6 -2
  36. package/src/api/when.ts +12 -5
  37. package/src/core/action.ts +8 -3
  38. package/src/core/computedvalue.ts +29 -9
  39. package/src/core/derivation.ts +25 -9
  40. package/src/core/globalstate.ts +18 -7
  41. package/src/core/observable.ts +14 -5
  42. package/src/core/reaction.ts +15 -6
  43. package/src/core/spy.ts +20 -7
  44. package/src/errors.ts +2 -2
  45. package/src/types/actionannotation.ts +2 -2
  46. package/src/types/dynamicobject.ts +10 -4
  47. package/src/types/flowannotation.ts +3 -1
  48. package/src/types/intercept-utils.ts +9 -3
  49. package/src/types/legacyobservablearray.ts +5 -3
  50. package/src/types/listen-utils.ts +6 -2
  51. package/src/types/modifiers.ts +39 -14
  52. package/src/types/observablearray.ts +78 -30
  53. package/src/types/observablemap.ts +60 -24
  54. package/src/types/observableobject.ts +52 -18
  55. package/src/types/observableset.ts +29 -10
  56. package/src/types/observablevalue.ts +13 -5
  57. package/src/types/type-utils.ts +33 -11
  58. package/src/utils/comparer.ts +4 -4
  59. package/src/utils/eq.ts +45 -15
  60. package/src/utils/utils.ts +42 -20
@@ -23,13 +23,23 @@ export interface IEnhancer<T> {
23
23
 
24
24
  export function deepEnhancer(v, _, name) {
25
25
  // it is an observable already, done
26
- if (isObservable(v)) return v
26
+ if (isObservable(v)) {
27
+ return v
28
+ }
27
29
 
28
30
  // something that can be converted and mutated?
29
- if (Array.isArray(v)) return observable.array(v, { name })
30
- if (isPlainObject(v)) return observable.object(v, undefined, { name })
31
- if (isES6Map(v)) return observable.map(v, { name })
32
- if (isES6Set(v)) return observable.set(v, { name })
31
+ if (Array.isArray(v)) {
32
+ return observable.array(v, { name })
33
+ }
34
+ if (isPlainObject(v)) {
35
+ return observable.object(v, undefined, { name })
36
+ }
37
+ if (isES6Map(v)) {
38
+ return observable.map(v, { name })
39
+ }
40
+ if (isES6Set(v)) {
41
+ return observable.set(v, { name })
42
+ }
33
43
  if (typeof v === "function" && !isAction(v) && !isFlow(v)) {
34
44
  if (isGenerator(v)) {
35
45
  return flow(v)
@@ -41,18 +51,30 @@ export function deepEnhancer(v, _, name) {
41
51
  }
42
52
 
43
53
  export function shallowEnhancer(v, _, name): any {
44
- if (v === undefined || v === null) return v
45
- if (isObservableObject(v) || isObservableArray(v) || isObservableMap(v) || isObservableSet(v))
54
+ if (v === undefined || v === null) {
55
+ return v
56
+ }
57
+ if (isObservableObject(v) || isObservableArray(v) || isObservableMap(v) || isObservableSet(v)) {
46
58
  return v
47
- if (Array.isArray(v)) return observable.array(v, { name, deep: false })
48
- if (isPlainObject(v)) return observable.object(v, undefined, { name, deep: false })
49
- if (isES6Map(v)) return observable.map(v, { name, deep: false })
50
- if (isES6Set(v)) return observable.set(v, { name, deep: false })
59
+ }
60
+ if (Array.isArray(v)) {
61
+ return observable.array(v, { name, deep: false })
62
+ }
63
+ if (isPlainObject(v)) {
64
+ return observable.object(v, undefined, { name, deep: false })
65
+ }
66
+ if (isES6Map(v)) {
67
+ return observable.map(v, { name, deep: false })
68
+ }
69
+ if (isES6Set(v)) {
70
+ return observable.set(v, { name, deep: false })
71
+ }
51
72
 
52
- if (__DEV__)
73
+ if (__DEV__) {
53
74
  die(
54
75
  "The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets"
55
76
  )
77
+ }
56
78
  }
57
79
 
58
80
  export function referenceEnhancer(newValue?) {
@@ -61,8 +83,11 @@ export function referenceEnhancer(newValue?) {
61
83
  }
62
84
 
63
85
  export function refStructEnhancer(v, oldValue): any {
64
- if (__DEV__ && isObservable(v))
86
+ if (__DEV__ && isObservable(v)) {
65
87
  die(`observable.struct should not be used with observable values`)
66
- if (deepEqual(v, oldValue)) return oldValue
88
+ }
89
+ if (deepEqual(v, oldValue)) {
90
+ return oldValue
91
+ }
67
92
  return v
68
93
  }
@@ -84,8 +84,12 @@ export interface IArrayWillSplice<T = any> {
84
84
  const arrayTraps = {
85
85
  get(target, name) {
86
86
  const adm: ObservableArrayAdministration = target[$mobx]
87
- if (name === $mobx) return adm
88
- if (name === "length") return adm.getArrayLength_()
87
+ if (name === $mobx) {
88
+ return adm
89
+ }
90
+ if (name === "length") {
91
+ return adm.getArrayLength_()
92
+ }
89
93
  if (typeof name === "string" && !isNaN(name as any)) {
90
94
  return adm.get_(parseInt(name))
91
95
  }
@@ -113,7 +117,8 @@ const arrayTraps = {
113
117
  }
114
118
 
115
119
  export class ObservableArrayAdministration
116
- implements IInterceptable<IArrayWillChange<any> | IArrayWillSplice<any>>, IListenable {
120
+ implements IInterceptable<IArrayWillChange<any> | IArrayWillSplice<any>>, IListenable
121
+ {
117
122
  atom_: IAtom
118
123
  readonly values_: any[] = [] // this is the prop that gets proxied, so can't replace it!
119
124
  interceptors_
@@ -135,13 +140,16 @@ export class ObservableArrayAdministration
135
140
  }
136
141
 
137
142
  dehanceValue_(value: any): any {
138
- if (this.dehancer !== undefined) return this.dehancer(value)
143
+ if (this.dehancer !== undefined) {
144
+ return this.dehancer(value)
145
+ }
139
146
  return value
140
147
  }
141
148
 
142
149
  dehanceValues_(values: any[]): any[] {
143
- if (this.dehancer !== undefined && values.length > 0)
150
+ if (this.dehancer !== undefined && values.length > 0) {
144
151
  return values.map(this.dehancer) as any
152
+ }
145
153
  return values
146
154
  }
147
155
 
@@ -175,36 +183,56 @@ export class ObservableArrayAdministration
175
183
  }
176
184
 
177
185
  setArrayLength_(newLength: number) {
178
- if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0)
186
+ if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) {
179
187
  die("Out of range: " + newLength)
188
+ }
180
189
  let currentLength = this.values_.length
181
- if (newLength === currentLength) return
182
- else if (newLength > currentLength) {
190
+ if (newLength === currentLength) {
191
+ return
192
+ } else if (newLength > currentLength) {
183
193
  const newItems = new Array(newLength - currentLength)
184
- for (let i = 0; i < newLength - currentLength; i++) newItems[i] = undefined // No Array.fill everywhere...
194
+ for (let i = 0; i < newLength - currentLength; i++) {
195
+ newItems[i] = undefined
196
+ } // No Array.fill everywhere...
185
197
  this.spliceWithArray_(currentLength, 0, newItems)
186
- } else this.spliceWithArray_(newLength, currentLength - newLength)
198
+ } else {
199
+ this.spliceWithArray_(newLength, currentLength - newLength)
200
+ }
187
201
  }
188
202
 
189
203
  updateArrayLength_(oldLength: number, delta: number) {
190
- if (oldLength !== this.lastKnownLength_) die(16)
204
+ if (oldLength !== this.lastKnownLength_) {
205
+ die(16)
206
+ }
191
207
  this.lastKnownLength_ += delta
192
- if (this.legacyMode_ && delta > 0) reserveArrayBuffer(oldLength + delta + 1)
208
+ if (this.legacyMode_ && delta > 0) {
209
+ reserveArrayBuffer(oldLength + delta + 1)
210
+ }
193
211
  }
194
212
 
195
213
  spliceWithArray_(index: number, deleteCount?: number, newItems?: any[]): any[] {
196
214
  checkIfStateModificationsAreAllowed(this.atom_)
197
215
  const length = this.values_.length
198
216
 
199
- if (index === undefined) index = 0
200
- else if (index > length) index = length
201
- else if (index < 0) index = Math.max(0, length + index)
217
+ if (index === undefined) {
218
+ index = 0
219
+ } else if (index > length) {
220
+ index = length
221
+ } else if (index < 0) {
222
+ index = Math.max(0, length + index)
223
+ }
202
224
 
203
- if (arguments.length === 1) deleteCount = length - index
204
- else if (deleteCount === undefined || deleteCount === null) deleteCount = 0
205
- else deleteCount = Math.max(0, Math.min(deleteCount, length - index))
225
+ if (arguments.length === 1) {
226
+ deleteCount = length - index
227
+ } else if (deleteCount === undefined || deleteCount === null) {
228
+ deleteCount = 0
229
+ } else {
230
+ deleteCount = Math.max(0, Math.min(deleteCount, length - index))
231
+ }
206
232
 
207
- if (newItems === undefined) newItems = EMPTY_ARRAY
233
+ if (newItems === undefined) {
234
+ newItems = EMPTY_ARRAY
235
+ }
208
236
 
209
237
  if (hasInterceptors(this)) {
210
238
  const change = interceptChange<IArrayWillSplice<any>>(this as any, {
@@ -214,7 +242,9 @@ export class ObservableArrayAdministration
214
242
  removedCount: deleteCount,
215
243
  added: newItems
216
244
  })
217
- if (!change) return EMPTY_ARRAY
245
+ if (!change) {
246
+ return EMPTY_ARRAY
247
+ }
218
248
  deleteCount = change.removedCount
219
249
  newItems = change.added
220
250
  }
@@ -227,8 +257,9 @@ export class ObservableArrayAdministration
227
257
  }
228
258
  const res = this.spliceItemsIntoValues_(index, deleteCount, newItems)
229
259
 
230
- if (deleteCount !== 0 || newItems.length !== 0)
260
+ if (deleteCount !== 0 || newItems.length !== 0) {
231
261
  this.notifyArraySplice_(index, newItems, res)
262
+ }
232
263
  return this.dehanceValues_(res)
233
264
  }
234
265
 
@@ -242,9 +273,12 @@ export class ObservableArrayAdministration
242
273
  let oldItems = this.values_.slice(index + deleteCount)
243
274
  // New length is the previous length + addition count - deletion count
244
275
  this.values_.length += newItems.length - deleteCount
245
- for (let i = 0; i < newItems.length; i++) this.values_[index + i] = newItems[i]
246
- for (let i = 0; i < oldItems.length; i++)
276
+ for (let i = 0; i < newItems.length; i++) {
277
+ this.values_[index + i] = newItems[i]
278
+ }
279
+ for (let i = 0; i < oldItems.length; i++) {
247
280
  this.values_[index + newItems.length + i] = oldItems[i]
281
+ }
248
282
  return res
249
283
  }
250
284
  }
@@ -267,10 +301,16 @@ export class ObservableArrayAdministration
267
301
 
268
302
  // The reason why this is on right hand side here (and not above), is this way the uglifier will drop it, but it won't
269
303
  // cause any runtime overhead in development mode without NODE_ENV set, unless spying is enabled
270
- if (__DEV__ && notifySpy) spyReportStart(change!)
304
+ if (__DEV__ && notifySpy) {
305
+ spyReportStart(change!)
306
+ }
271
307
  this.atom_.reportChanged()
272
- if (notify) notifyListeners(this, change)
273
- if (__DEV__ && notifySpy) spyReportEnd()
308
+ if (notify) {
309
+ notifyListeners(this, change)
310
+ }
311
+ if (__DEV__ && notifySpy) {
312
+ spyReportEnd()
313
+ }
274
314
  }
275
315
 
276
316
  notifyArraySplice_(index: number, added: any[], removed: any[]) {
@@ -291,11 +331,17 @@ export class ObservableArrayAdministration
291
331
  } as const)
292
332
  : null
293
333
 
294
- if (__DEV__ && notifySpy) spyReportStart(change!)
334
+ if (__DEV__ && notifySpy) {
335
+ spyReportStart(change!)
336
+ }
295
337
  this.atom_.reportChanged()
296
338
  // conform: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe
297
- if (notify) notifyListeners(this, change)
298
- if (__DEV__ && notifySpy) spyReportEnd()
339
+ if (notify) {
340
+ notifyListeners(this, change)
341
+ }
342
+ if (__DEV__ && notifySpy) {
343
+ spyReportEnd()
344
+ }
299
345
  }
300
346
 
301
347
  get_(index: number): any | undefined {
@@ -323,7 +369,9 @@ export class ObservableArrayAdministration
323
369
  index,
324
370
  newValue
325
371
  })
326
- if (!change) return
372
+ if (!change) {
373
+ return
374
+ }
327
375
  newValue = change.newValue
328
376
  }
329
377
  newValue = this.enhancer_(newValue, oldValue)
@@ -118,7 +118,9 @@ export class ObservableMap<K = any, V = any>
118
118
  }
119
119
 
120
120
  has(key: K): boolean {
121
- if (!globalState.trackingDerivation) return this.has_(key)
121
+ if (!globalState.trackingDerivation) {
122
+ return this.has_(key)
123
+ }
122
124
 
123
125
  let entry = this.hasMap_.get(key)
124
126
  if (!entry) {
@@ -144,7 +146,9 @@ export class ObservableMap<K = any, V = any>
144
146
  newValue: value,
145
147
  name: key
146
148
  })
147
- if (!change) return this
149
+ if (!change) {
150
+ return this
151
+ }
148
152
  value = change.newValue!
149
153
  }
150
154
  if (hasKey) {
@@ -163,7 +167,9 @@ export class ObservableMap<K = any, V = any>
163
167
  object: this,
164
168
  name: key
165
169
  })
166
- if (!change) return false
170
+ if (!change) {
171
+ return false
172
+ }
167
173
  }
168
174
  if (this.has_(key)) {
169
175
  const notifySpy = isSpyEnabled()
@@ -180,7 +186,9 @@ export class ObservableMap<K = any, V = any>
180
186
  }
181
187
  : null
182
188
 
183
- if (__DEV__ && notifySpy) spyReportStart(change! as PureSpyEvent) // TODO fix type
189
+ if (__DEV__ && notifySpy) {
190
+ spyReportStart(change! as PureSpyEvent)
191
+ } // TODO fix type
184
192
  transaction(() => {
185
193
  this.keysAtom_.reportChanged()
186
194
  this.hasMap_.get(key)?.setNewValue_(false)
@@ -188,8 +196,12 @@ export class ObservableMap<K = any, V = any>
188
196
  observable.setNewValue_(undefined as any)
189
197
  this.data_.delete(key)
190
198
  })
191
- if (notify) notifyListeners(this, change)
192
- if (__DEV__ && notifySpy) spyReportEnd()
199
+ if (notify) {
200
+ notifyListeners(this, change)
201
+ }
202
+ if (__DEV__ && notifySpy) {
203
+ spyReportEnd()
204
+ }
193
205
  return true
194
206
  }
195
207
  return false
@@ -213,10 +225,16 @@ export class ObservableMap<K = any, V = any>
213
225
  newValue
214
226
  }
215
227
  : null
216
- if (__DEV__ && notifySpy) spyReportStart(change! as PureSpyEvent) // TODO fix type
228
+ if (__DEV__ && notifySpy) {
229
+ spyReportStart(change! as PureSpyEvent)
230
+ } // TODO fix type
217
231
  observable.setNewValue_(newValue as V)
218
- if (notify) notifyListeners(this, change)
219
- if (__DEV__ && notifySpy) spyReportEnd()
232
+ if (notify) {
233
+ notifyListeners(this, change)
234
+ }
235
+ if (__DEV__ && notifySpy) {
236
+ spyReportEnd()
237
+ }
220
238
  }
221
239
  }
222
240
 
@@ -247,13 +265,21 @@ export class ObservableMap<K = any, V = any>
247
265
  newValue
248
266
  }
249
267
  : null
250
- if (__DEV__ && notifySpy) spyReportStart(change! as PureSpyEvent) // TODO fix type
251
- if (notify) notifyListeners(this, change)
252
- if (__DEV__ && notifySpy) spyReportEnd()
268
+ if (__DEV__ && notifySpy) {
269
+ spyReportStart(change! as PureSpyEvent)
270
+ } // TODO fix type
271
+ if (notify) {
272
+ notifyListeners(this, change)
273
+ }
274
+ if (__DEV__ && notifySpy) {
275
+ spyReportEnd()
276
+ }
253
277
  }
254
278
 
255
279
  get(key: K): V | undefined {
256
- if (this.has(key)) return this.dehanceValue_(this.data_.get(key)!.get())
280
+ if (this.has(key)) {
281
+ return this.dehanceValue_(this.data_.get(key)!.get())
282
+ }
257
283
  return this.dehanceValue_(undefined)
258
284
  }
259
285
 
@@ -302,24 +328,31 @@ export class ObservableMap<K = any, V = any>
302
328
  }
303
329
 
304
330
  forEach(callback: (value: V, key: K, object: Map<K, V>) => void, thisArg?) {
305
- for (const [key, value] of this) callback.call(thisArg, value, key, this)
331
+ for (const [key, value] of this) {
332
+ callback.call(thisArg, value, key, this)
333
+ }
306
334
  }
307
335
 
308
336
  /** Merge another object into this object, returns this. */
309
- merge(other: ObservableMap<K, V> | IKeyValueMap<V> | any): ObservableMap<K, V> {
337
+ merge(other?: IObservableMapInitialValues<K, V>): ObservableMap<K, V> {
310
338
  if (isObservableMap(other)) {
311
339
  other = new Map(other)
312
340
  }
313
341
  transaction(() => {
314
- if (isPlainObject(other))
342
+ if (isPlainObject(other)) {
315
343
  getPlainObjectKeys(other).forEach((key: any) =>
316
- this.set(key as any as K, other[key])
344
+ this.set(key as K, (other as IKeyValueMap)[key])
317
345
  )
318
- else if (Array.isArray(other)) other.forEach(([key, value]) => this.set(key, value))
319
- else if (isES6Map(other)) {
320
- if (other.constructor !== Map) die(19, other)
346
+ } else if (Array.isArray(other)) {
347
+ other.forEach(([key, value]) => this.set(key, value))
348
+ } else if (isES6Map(other)) {
349
+ if (other.constructor !== Map) {
350
+ die(19, other)
351
+ }
321
352
  other.forEach((value, key) => this.set(key, value))
322
- } else if (other !== null && other !== undefined) die(20, other)
353
+ } else if (other !== null && other !== undefined) {
354
+ die(20, other)
355
+ }
323
356
  })
324
357
  return this
325
358
  }
@@ -327,12 +360,14 @@ export class ObservableMap<K = any, V = any>
327
360
  clear() {
328
361
  transaction(() => {
329
362
  untracked(() => {
330
- for (const key of this.keys()) this.delete(key)
363
+ for (const key of this.keys()) {
364
+ this.delete(key)
365
+ }
331
366
  })
332
367
  })
333
368
  }
334
369
 
335
- replace(values: ObservableMap<K, V> | IKeyValueMap<V> | any): ObservableMap<K, V> {
370
+ replace(values: IObservableMapInitialValues<K, V>): ObservableMap<K, V> {
336
371
  // Implementation requirements:
337
372
  // - respect ordering of replacement map
338
373
  // - allow interceptors to run and potentially prevent individual operations
@@ -433,8 +468,9 @@ export class ObservableMap<K = any, V = any>
433
468
  * for callback details
434
469
  */
435
470
  observe_(listener: (changes: IMapDidChange<K, V>) => void, fireImmediately?: boolean): Lambda {
436
- if (__DEV__ && fireImmediately === true)
471
+ if (__DEV__ && fireImmediately === true) {
437
472
  die("`observe` doesn't support fireImmediately=true in combination with maps.")
473
+ }
438
474
  return registerListener(this, listener)
439
475
  }
440
476
 
@@ -136,7 +136,9 @@ export class ObservableObjectAdministration
136
136
  name: key,
137
137
  newValue
138
138
  })
139
- if (!change) return null
139
+ if (!change) {
140
+ return null
141
+ }
140
142
  newValue = (change as any).newValue
141
143
  }
142
144
  newValue = (observable as any).prepareNewValue_(newValue)
@@ -158,10 +160,16 @@ export class ObservableObjectAdministration
158
160
  }
159
161
  : null
160
162
 
161
- if (__DEV__ && notifySpy) spyReportStart(change!)
163
+ if (__DEV__ && notifySpy) {
164
+ spyReportStart(change!)
165
+ }
162
166
  ;(observable as ObservableValue<any>).setNewValue_(newValue)
163
- if (notify) notifyListeners(this, change)
164
- if (__DEV__ && notifySpy) spyReportEnd()
167
+ if (notify) {
168
+ notifyListeners(this, change)
169
+ }
170
+ if (__DEV__ && notifySpy) {
171
+ spyReportEnd()
172
+ }
165
173
  }
166
174
  return true
167
175
  }
@@ -256,8 +264,12 @@ export class ObservableObjectAdministration
256
264
  const descriptor = getDescriptor(source, key)
257
265
  if (descriptor) {
258
266
  const outcome = annotation.make_(this, key, descriptor, source)
259
- if (outcome === MakeResult.Cancel) return
260
- if (outcome === MakeResult.Break) break
267
+ if (outcome === MakeResult.Cancel) {
268
+ return
269
+ }
270
+ if (outcome === MakeResult.Break) {
271
+ break
272
+ }
261
273
  }
262
274
  source = Object.getPrototypeOf(source)
263
275
  }
@@ -320,7 +332,9 @@ export class ObservableObjectAdministration
320
332
  type: ADD,
321
333
  newValue: descriptor.value
322
334
  })
323
- if (!change) return null
335
+ if (!change) {
336
+ return null
337
+ }
324
338
  const { newValue } = change as any
325
339
  if (descriptor.value !== newValue) {
326
340
  descriptor = {
@@ -372,7 +386,9 @@ export class ObservableObjectAdministration
372
386
  type: ADD,
373
387
  newValue: value
374
388
  })
375
- if (!change) return null
389
+ if (!change) {
390
+ return null
391
+ }
376
392
  value = (change as any).newValue
377
393
  }
378
394
 
@@ -434,7 +450,9 @@ export class ObservableObjectAdministration
434
450
  type: ADD,
435
451
  newValue: undefined
436
452
  })
437
- if (!change) return null
453
+ if (!change) {
454
+ return null
455
+ }
438
456
  }
439
457
  options.name ||= __DEV__ ? `${this.name_}.${key.toString()}` : "ObservableObject.key"
440
458
  options.context = this.proxy_ || this.target_
@@ -485,7 +503,9 @@ export class ObservableObjectAdministration
485
503
  type: REMOVE
486
504
  })
487
505
  // Cancelled
488
- if (!change) return null
506
+ if (!change) {
507
+ return null
508
+ }
489
509
  }
490
510
 
491
511
  // Delete
@@ -539,9 +559,15 @@ export class ObservableObjectAdministration
539
559
  oldValue: value,
540
560
  name: key
541
561
  }
542
- if (__DEV__ && notifySpy) spyReportStart(change!)
543
- if (notify) notifyListeners(this, change)
544
- if (__DEV__ && notifySpy) spyReportEnd()
562
+ if (__DEV__ && notifySpy) {
563
+ spyReportStart(change!)
564
+ }
565
+ if (notify) {
566
+ notifyListeners(this, change)
567
+ }
568
+ if (__DEV__ && notifySpy) {
569
+ spyReportEnd()
570
+ }
545
571
  }
546
572
  } finally {
547
573
  endBatch()
@@ -555,8 +581,9 @@ export class ObservableObjectAdministration
555
581
  * for callback details
556
582
  */
557
583
  observe_(callback: (changes: IObjectDidChange) => void, fireImmediately?: boolean): Lambda {
558
- if (__DEV__ && fireImmediately === true)
584
+ if (__DEV__ && fireImmediately === true) {
559
585
  die("`observe` doesn't support the fire immediately property for observable objects.")
586
+ }
560
587
  return registerListener(this, callback)
561
588
  }
562
589
 
@@ -580,9 +607,15 @@ export class ObservableObjectAdministration
580
607
  } as const)
581
608
  : null
582
609
 
583
- if (__DEV__ && notifySpy) spyReportStart(change!)
584
- if (notify) notifyListeners(this, change)
585
- if (__DEV__ && notifySpy) spyReportEnd()
610
+ if (__DEV__ && notifySpy) {
611
+ spyReportStart(change!)
612
+ }
613
+ if (notify) {
614
+ notifyListeners(this, change)
615
+ }
616
+ if (__DEV__ && notifySpy) {
617
+ spyReportEnd()
618
+ }
586
619
  }
587
620
 
588
621
  this.pendingKeys_?.get(key)?.set(true)
@@ -631,8 +664,9 @@ export function asObservableObject(
631
664
  return target
632
665
  }
633
666
 
634
- if (__DEV__ && !Object.isExtensible(target))
667
+ if (__DEV__ && !Object.isExtensible(target)) {
635
668
  die("Cannot make the designated object observable; it is not extensible")
669
+ }
636
670
 
637
671
  const name =
638
672
  options?.name ??
@@ -96,7 +96,9 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
96
96
  clear() {
97
97
  transaction(() => {
98
98
  untracked(() => {
99
- for (const value of this.data_.values()) this.delete(value)
99
+ for (const value of this.data_.values()) {
100
+ this.delete(value)
101
+ }
100
102
  })
101
103
  })
102
104
  }
@@ -120,7 +122,9 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
120
122
  object: this,
121
123
  newValue: value
122
124
  })
123
- if (!change) return this
125
+ if (!change) {
126
+ return this
127
+ }
124
128
  // ideally, value = change.value would be done here, so that values can be
125
129
  // changed by interceptor. Same applies for other Set and Map api's.
126
130
  }
@@ -141,9 +145,15 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
141
145
  newValue: value
142
146
  }
143
147
  : null
144
- if (notifySpy && __DEV__) spyReportStart(change!)
145
- if (notify) notifyListeners(this, change)
146
- if (notifySpy && __DEV__) spyReportEnd()
148
+ if (notifySpy && __DEV__) {
149
+ spyReportStart(change!)
150
+ }
151
+ if (notify) {
152
+ notifyListeners(this, change)
153
+ }
154
+ if (notifySpy && __DEV__) {
155
+ spyReportEnd()
156
+ }
147
157
  }
148
158
 
149
159
  return this
@@ -156,7 +166,9 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
156
166
  object: this,
157
167
  oldValue: value
158
168
  })
159
- if (!change) return false
169
+ if (!change) {
170
+ return false
171
+ }
160
172
  }
161
173
  if (this.has(value)) {
162
174
  const notifySpy = __DEV__ && isSpyEnabled()
@@ -172,13 +184,19 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
172
184
  }
173
185
  : null
174
186
 
175
- if (notifySpy && __DEV__) spyReportStart(change!)
187
+ if (notifySpy && __DEV__) {
188
+ spyReportStart(change!)
189
+ }
176
190
  transaction(() => {
177
191
  this.atom_.reportChanged()
178
192
  this.data_.delete(value)
179
193
  })
180
- if (notify) notifyListeners(this, change)
181
- if (notifySpy && __DEV__) spyReportEnd()
194
+ if (notify) {
195
+ notifyListeners(this, change)
196
+ }
197
+ if (notifySpy && __DEV__) {
198
+ spyReportEnd()
199
+ }
182
200
  return true
183
201
  }
184
202
  return false
@@ -243,8 +261,9 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
243
261
  }
244
262
  observe_(listener: (changes: ISetDidChange<T>) => void, fireImmediately?: boolean): Lambda {
245
263
  // ... 'fireImmediately' could also be true?
246
- if (__DEV__ && fireImmediately === true)
264
+ if (__DEV__ && fireImmediately === true) {
247
265
  die("`observe` doesn't support fireImmediately=true in combination with sets.")
266
+ }
248
267
  return registerListener(this, listener)
249
268
  }
250
269