mobx 6.16.1 → 7.0.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 (98) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +9 -13
  3. package/dist/api/action.d.ts +6 -4
  4. package/dist/api/annotation.d.ts +0 -1
  5. package/dist/api/computed.d.ts +4 -7
  6. package/dist/api/configure.d.ts +0 -1
  7. package/dist/api/decoratorannotation.d.ts +3 -0
  8. package/dist/api/decorators.d.ts +0 -19
  9. package/dist/api/flow.d.ts +4 -5
  10. package/dist/api/makeObservable.d.ts +2 -3
  11. package/dist/api/observable.d.ts +9 -15
  12. package/dist/core/atom.d.ts +0 -3
  13. package/dist/core/computedvalue.d.ts +4 -32
  14. package/dist/core/derivation.d.ts +1 -7
  15. package/dist/core/globalstate.d.ts +0 -2
  16. package/dist/core/reaction.d.ts +1 -9
  17. package/dist/errors.d.ts +6 -4
  18. package/dist/internal.d.ts +1 -4
  19. package/dist/mobx.cjs.development.js +1630 -2447
  20. package/dist/mobx.cjs.development.js.map +1 -1
  21. package/dist/mobx.cjs.production.min.js +1 -1
  22. package/dist/mobx.cjs.production.min.js.map +1 -1
  23. package/dist/mobx.d.ts +2 -2
  24. package/dist/mobx.esm.development.js +1619 -2446
  25. package/dist/mobx.esm.development.js.map +1 -1
  26. package/dist/mobx.esm.js +1567 -2397
  27. package/dist/mobx.esm.js.map +1 -1
  28. package/dist/mobx.esm.production.min.js +1 -1
  29. package/dist/mobx.esm.production.min.js.map +1 -1
  30. package/dist/mobx.mjs +5271 -0
  31. package/dist/mobx.mjs.map +1 -0
  32. package/dist/mobx.umd.development.js +1633 -2450
  33. package/dist/mobx.umd.development.js.map +1 -1
  34. package/dist/mobx.umd.production.min.js +1 -1
  35. package/dist/mobx.umd.production.min.js.map +1 -1
  36. package/dist/types/actionannotation.d.ts +1 -0
  37. package/dist/types/computedannotation.d.ts +1 -0
  38. package/dist/types/decorator_fills.d.ts +2 -0
  39. package/dist/types/flowannotation.d.ts +1 -0
  40. package/dist/types/observableannotation.d.ts +5 -0
  41. package/dist/types/observablearray.d.ts +2 -5
  42. package/dist/types/observablemap.d.ts +1 -8
  43. package/dist/types/observableobject.d.ts +2 -13
  44. package/dist/types/observableset.d.ts +1 -3
  45. package/dist/types/observablevalue.d.ts +4 -6
  46. package/dist/types/overrideannotation.d.ts +1 -2
  47. package/dist/utils/comparer.d.ts +4 -11
  48. package/dist/utils/utils.d.ts +0 -2
  49. package/package.json +25 -15
  50. package/src/api/action.ts +27 -35
  51. package/src/api/annotation.ts +0 -1
  52. package/src/api/autorun.ts +2 -4
  53. package/src/api/computed.ts +21 -28
  54. package/src/api/configure.ts +1 -15
  55. package/src/api/decoratorannotation.ts +20 -0
  56. package/src/api/decorators.ts +1 -85
  57. package/src/api/extras.ts +1 -1
  58. package/src/api/flow.ts +26 -29
  59. package/src/api/intercept.ts +4 -3
  60. package/src/api/makeObservable.ts +45 -17
  61. package/src/api/object-api.ts +1 -1
  62. package/src/api/observable.ts +34 -67
  63. package/src/api/observe.ts +82 -3
  64. package/src/api/when.ts +4 -3
  65. package/src/core/action.ts +12 -5
  66. package/src/core/atom.ts +14 -13
  67. package/src/core/computedvalue.ts +27 -67
  68. package/src/core/derivation.ts +15 -14
  69. package/src/core/globalstate.ts +8 -13
  70. package/src/core/observable.ts +0 -48
  71. package/src/core/reaction.ts +19 -25
  72. package/src/core/spy.ts +3 -3
  73. package/src/errors.ts +23 -12
  74. package/src/internal.ts +1 -4
  75. package/src/mobx.ts +21 -10
  76. package/src/types/actionannotation.ts +5 -9
  77. package/src/types/autoannotation.ts +8 -11
  78. package/src/types/computedannotation.ts +13 -11
  79. package/src/types/decorator_fills.ts +4 -0
  80. package/src/types/dynamicobject.ts +0 -29
  81. package/src/types/flowannotation.ts +7 -4
  82. package/src/types/observableannotation.ts +6 -7
  83. package/src/types/observablearray.ts +8 -61
  84. package/src/types/observablemap.ts +4 -29
  85. package/src/types/observableobject.ts +5 -70
  86. package/src/types/observableset.ts +5 -28
  87. package/src/types/observablevalue.ts +7 -29
  88. package/src/types/overrideannotation.ts +7 -22
  89. package/src/types/type-utils.ts +4 -2
  90. package/src/utils/comparer.ts +4 -17
  91. package/src/utils/iterable.ts +3 -4
  92. package/src/utils/utils.ts +4 -46
  93. package/dist/api/trace.d.ts +0 -3
  94. package/dist/types/legacyobservablearray.d.ts +0 -14
  95. package/dist/utils/global.d.ts +0 -1
  96. package/src/api/trace.ts +0 -35
  97. package/src/types/legacyobservablearray.ts +0 -155
  98. package/src/utils/global.ts +0 -20
@@ -12,7 +12,6 @@ import {
12
12
  IEnhancer,
13
13
  IInterceptable,
14
14
  IListenable,
15
- Lambda,
16
15
  ObservableValue,
17
16
  addHiddenProp,
18
17
  createInstanceofPredicate,
@@ -26,8 +25,6 @@ import {
26
25
  isSpyEnabled,
27
26
  notifyListeners,
28
27
  referenceEnhancer,
29
- registerInterceptor,
30
- registerListener,
31
28
  spyReportEnd,
32
29
  spyReportStart,
33
30
  startBatch,
@@ -38,16 +35,14 @@ import {
38
35
  die,
39
36
  hasProp,
40
37
  getDescriptor,
41
- storedAnnotationsSymbol,
42
38
  ownKeys,
43
39
  isOverride,
44
40
  defineProperty,
45
41
  autoAnnotation,
46
42
  getAdministration,
47
43
  getDebugName,
48
- objectPrototype,
49
- MakeResult,
50
- checkIfStateModificationsAreAllowed
44
+ checkIfStateModificationsAreAllowed,
45
+ assign
51
46
  } from "../internal"
52
47
 
53
48
  const descriptorCache = Object.create(null)
@@ -274,47 +269,6 @@ export class ObservableObjectAdministration
274
269
  return entry.get()
275
270
  }
276
271
 
277
- /**
278
- * @param {PropertyKey} key
279
- * @param {Annotation|boolean} annotation true - use default annotation, false - ignore prop
280
- */
281
- make_(key: PropertyKey, annotation: Annotation | boolean): void {
282
- if (annotation === true) {
283
- annotation = this.defaultAnnotation_
284
- }
285
- if (annotation === false) {
286
- return
287
- }
288
- assertAnnotable(this, annotation, key)
289
- if (!(key in this.target_)) {
290
- // Throw on missing key, except for decorators:
291
- // Decorator annotations are collected from whole prototype chain.
292
- // When called from super() some props may not exist yet.
293
- // However we don't have to worry about missing prop,
294
- // because the decorator must have been applied to something.
295
- if (this.target_[storedAnnotationsSymbol]?.[key]) {
296
- return // will be annotated by subclass constructor
297
- } else {
298
- die(1, annotation.annotationType_, `${this.name_}.${key.toString()}`)
299
- }
300
- }
301
- let source = this.target_
302
- while (source && source !== objectPrototype) {
303
- const descriptor = getDescriptor(source, key)
304
- if (descriptor) {
305
- const outcome = annotation.make_(this, key, descriptor, source)
306
- if (outcome === MakeResult.Cancel) {
307
- return
308
- }
309
- if (outcome === MakeResult.Break) {
310
- break
311
- }
312
- }
313
- source = Object.getPrototypeOf(source)
314
- }
315
- recordAnnotationApplied(this, annotation, key)
316
- }
317
-
318
272
  /**
319
273
  * @param {PropertyKey} key
320
274
  * @param {PropertyDescriptor} descriptor
@@ -377,10 +331,9 @@ export class ObservableObjectAdministration
377
331
  }
378
332
  const { newValue } = change as any
379
333
  if (descriptor.value !== newValue) {
380
- descriptor = {
381
- ...descriptor,
334
+ descriptor = assign({}, descriptor, {
382
335
  value: newValue
383
- }
336
+ })
384
337
  }
385
338
  }
386
339
 
@@ -618,22 +571,6 @@ export class ObservableObjectAdministration
618
571
  return true
619
572
  }
620
573
 
621
- /**
622
- * Observes this object. Triggers for the events 'add', 'update' and 'delete'.
623
- * See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/observe
624
- * for callback details
625
- */
626
- observe_(callback: (changes: IObjectDidChange) => void, fireImmediately?: boolean): Lambda {
627
- if (__DEV__ && fireImmediately === true) {
628
- die("`observe` doesn't support the fire immediately property for observable objects.")
629
- }
630
- return registerListener(this, callback)
631
- }
632
-
633
- intercept_(handler): Lambda {
634
- return registerInterceptor(this, handler)
635
- }
636
-
637
574
  notifyPropertyAddition_(key: PropertyKey, value: any) {
638
575
  const notify = hasListeners(this)
639
576
  const notifySpy = __DEV__ && isSpyEnabled()
@@ -765,11 +702,9 @@ export function recordAnnotationApplied(
765
702
  if (__DEV__) {
766
703
  adm.appliedAnnotations_![key] = annotation
767
704
  }
768
- // Remove applied decorator annotation so we don't try to apply it again in subclass constructor
769
- delete adm.target_[storedAnnotationsSymbol]?.[key]
770
705
  }
771
706
 
772
- function assertAnnotable(
707
+ export function assertAnnotable(
773
708
  adm: ObservableObjectAdministration,
774
709
  annotation: Annotation,
775
710
  key: PropertyKey
@@ -7,8 +7,6 @@ import {
7
7
  isSpyEnabled,
8
8
  hasListeners,
9
9
  IListenable,
10
- registerListener,
11
- Lambda,
12
10
  spyReportStart,
13
11
  notifyListeners,
14
12
  spyReportEnd,
@@ -17,8 +15,6 @@ import {
17
15
  hasInterceptors,
18
16
  interceptChange,
19
17
  IInterceptable,
20
- IInterceptor,
21
- registerInterceptor,
22
18
  checkIfStateModificationsAreAllowed,
23
19
  untracked,
24
20
  transaction,
@@ -27,7 +23,6 @@ import {
27
23
  DELETE,
28
24
  ADD,
29
25
  die,
30
- isFunction,
31
26
  initObservable
32
27
  } from "../internal"
33
28
 
@@ -55,16 +50,14 @@ export type ISetWillDeleteChange<T = any> = {
55
50
  type: "delete"
56
51
  object: ObservableSet<T>
57
52
  oldValue: T
58
- };
53
+ }
59
54
  export type ISetWillAddChange<T = any> = {
60
55
  type: "add"
61
56
  object: ObservableSet<T>
62
57
  newValue: T
63
- };
58
+ }
64
59
 
65
- export type ISetWillChange<T = any> =
66
- | ISetWillDeleteChange<T>
67
- | ISetWillAddChange<T>
60
+ export type ISetWillChange<T = any> = ISetWillDeleteChange<T> | ISetWillAddChange<T>
68
61
 
69
62
  export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillChange>, IListenable {
70
63
  [$mobx] = ObservableSetMarker
@@ -80,9 +73,6 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
80
73
  enhancer: IEnhancer<T> = deepEnhancer,
81
74
  public name_ = __DEV__ ? "ObservableSet@" + getNextId() : "ObservableSet"
82
75
  ) {
83
- if (!isFunction(Set)) {
84
- die(22)
85
- }
86
76
  this.enhancer_ = (newV, oldV) => enhancer(newV, oldV, name_)
87
77
  initObservable(() => {
88
78
  this.atom_ = createAtom(this.name_)
@@ -133,8 +123,7 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
133
123
  }
134
124
 
135
125
  // implemented reassignment same as it's done for ObservableMap
136
- value = change.newValue!;
137
-
126
+ value = change.newValue!
138
127
  }
139
128
  if (!this.has(value)) {
140
129
  transaction(() => {
@@ -304,24 +293,12 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
304
293
  this.clear()
305
294
  other.forEach(value => this.add(value))
306
295
  } else if (other !== null && other !== undefined) {
307
- die("Cannot initialize set from " + other)
296
+ die(41, other)
308
297
  }
309
298
  })
310
299
 
311
300
  return this
312
301
  }
313
- observe_(listener: (changes: ISetDidChange<T>) => void, fireImmediately?: boolean): Lambda {
314
- // ... 'fireImmediately' could also be true?
315
- if (__DEV__ && fireImmediately === true) {
316
- die("`observe` doesn't support fireImmediately=true in combination with sets.")
317
- }
318
- return registerListener(this, listener)
319
- }
320
-
321
- intercept_(handler: IInterceptor<ISetWillChange<T>>): Lambda {
322
- return registerInterceptor(this, handler)
323
- }
324
-
325
302
  toJSON(): T[] {
326
303
  return Array.from(this)
327
304
  }
@@ -3,11 +3,9 @@ import {
3
3
  IEnhancer,
4
4
  IInterceptable,
5
5
  IEqualsComparer,
6
- IInterceptor,
7
6
  IListenable,
8
- Lambda,
9
7
  checkIfStateModificationsAreAllowed,
10
- comparer,
8
+ compareDefault,
11
9
  createInstanceofPredicate,
12
10
  getNextId,
13
11
  hasInterceptors,
@@ -15,8 +13,6 @@ import {
15
13
  interceptChange,
16
14
  isSpyEnabled,
17
15
  notifyListeners,
18
- registerInterceptor,
19
- registerListener,
20
16
  spyReport,
21
17
  spyReportEnd,
22
18
  spyReportStart,
@@ -69,13 +65,13 @@ export class ObservableValue<T>
69
65
 
70
66
  constructor(
71
67
  value: T,
72
- public enhancer: IEnhancer<T>,
68
+ public enhancer_: IEnhancer<T>,
73
69
  public name_ = __DEV__ ? "ObservableValue@" + getNextId() : "ObservableValue",
74
70
  notifySpy = true,
75
- private equals: IEqualsComparer<any> = comparer.default
71
+ private equals_: IEqualsComparer<any> = compareDefault
76
72
  ) {
77
73
  super(name_)
78
- this.value_ = enhancer(value, undefined, name_)
74
+ this.value_ = enhancer_(value, undefined, name_)
79
75
  if (__DEV__ && notifySpy && isSpyEnabled()) {
80
76
  // only notify spy if this is a stand-alone observable
81
77
  spyReport({
@@ -99,7 +95,7 @@ export class ObservableValue<T>
99
95
  const oldValue = this.value_
100
96
  newValue = this.prepareNewValue_(newValue) as any
101
97
  if (newValue !== globalState.UNCHANGED) {
102
- const notifySpy = isSpyEnabled()
98
+ const notifySpy = __DEV__ && isSpyEnabled()
103
99
  if (__DEV__ && notifySpy) {
104
100
  spyReportStart({
105
101
  type: UPDATE,
@@ -131,8 +127,8 @@ export class ObservableValue<T>
131
127
  newValue = change.newValue
132
128
  }
133
129
  // apply modifier
134
- newValue = this.enhancer(newValue, this.value_, this.name_)
135
- return this.equals(this.value_, newValue) ? globalState.UNCHANGED : newValue
130
+ newValue = this.enhancer_(newValue, this.value_, this.name_)
131
+ return this.equals_(this.value_, newValue) ? globalState.UNCHANGED : newValue
136
132
  }
137
133
 
138
134
  setNewValue_(newValue: T) {
@@ -154,24 +150,6 @@ export class ObservableValue<T>
154
150
  return this.dehanceValue(this.value_)
155
151
  }
156
152
 
157
- intercept_(handler: IInterceptor<IValueWillChange<T>>): Lambda {
158
- return registerInterceptor(this, handler)
159
- }
160
-
161
- observe_(listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda {
162
- if (fireImmediately) {
163
- listener({
164
- observableKind: "value",
165
- debugObjectName: this.name_,
166
- object: this,
167
- type: UPDATE,
168
- newValue: this.value_,
169
- oldValue: undefined
170
- })
171
- }
172
- return registerListener(this, listener)
173
- }
174
-
175
153
  raw() {
176
154
  // used by MST ot get undehanced value
177
155
  return this.value_
@@ -1,23 +1,12 @@
1
- import {
2
- die,
3
- Annotation,
4
- hasProp,
5
- createDecoratorAnnotation,
6
- ObservableObjectAdministration,
7
- MakeResult
8
- } from "../internal"
9
-
10
- import type { ClassMethodDecorator } from "./decorator_fills"
1
+ import { die, Annotation, hasProp, ObservableObjectAdministration, MakeResult } from "../internal"
11
2
 
12
3
  const OVERRIDE = "override"
13
4
 
14
- export const override: Annotation & PropertyDecorator & ClassMethodDecorator =
15
- createDecoratorAnnotation({
16
- annotationType_: OVERRIDE,
17
- make_,
18
- extend_,
19
- decorate_20223_
20
- })
5
+ export const override: Annotation = {
6
+ annotationType_: OVERRIDE,
7
+ make_,
8
+ extend_
9
+ }
21
10
 
22
11
  export function isOverride(annotation: Annotation): boolean {
23
12
  return annotation.annotationType_ === OVERRIDE
@@ -42,9 +31,5 @@ function make_(this: Annotation, adm: ObservableObjectAdministration, key): Make
42
31
  }
43
32
 
44
33
  function extend_(this: Annotation, adm, key, descriptor, proxyTrap): boolean {
45
- die(`'${this.annotationType_}' can only be used with 'makeObservable'`)
46
- }
47
-
48
- function decorate_20223_(this: Annotation, desc, context: DecoratorContext) {
49
- console.warn(`'${this.annotationType_}' cannot be used with decorators - this is a no-op`)
34
+ die(44, this.annotationType_)
50
35
  }
@@ -111,13 +111,15 @@ export function getDebugName(thing: any, property?: string): string {
111
111
  */
112
112
  export function initObservable<T>(cb: () => T): T {
113
113
  const derivation = untrackedStart()
114
- const allowStateChanges = allowStateChangesStart(true)
114
+ const allowStateChanges = __DEV__ ? allowStateChangesStart(true) : true
115
115
  startBatch()
116
116
  try {
117
117
  return cb()
118
118
  } finally {
119
119
  endBatch()
120
- allowStateChangesEnd(allowStateChanges)
120
+ if (__DEV__) {
121
+ allowStateChangesEnd(allowStateChanges)
122
+ }
121
123
  untrackedEnd(derivation)
122
124
  }
123
125
  }
@@ -4,29 +4,16 @@ export interface IEqualsComparer<T> {
4
4
  (a: T, b: T): boolean
5
5
  }
6
6
 
7
- function identityComparer(a: any, b: any): boolean {
7
+ export function compareIdentity(a: any, b: any): boolean {
8
8
  return a === b
9
9
  }
10
10
 
11
- function structuralComparer(a: any, b: any): boolean {
11
+ export function compareStructural(a: any, b: any): boolean {
12
12
  return deepEqual(a, b)
13
13
  }
14
14
 
15
- function shallowComparer(a: any, b: any): boolean {
15
+ export function compareShallow(a: any, b: any): boolean {
16
16
  return deepEqual(a, b, 1)
17
17
  }
18
18
 
19
- function defaultComparer(a: any, b: any): boolean {
20
- if (Object.is) {
21
- return Object.is(a, b)
22
- }
23
-
24
- return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b
25
- }
26
-
27
- export const comparer = {
28
- identity: identityComparer,
29
- structural: structuralComparer,
30
- default: defaultComparer,
31
- shallow: shallowComparer
32
- }
19
+ export const compareDefault = Object.is
@@ -1,14 +1,13 @@
1
- import { getGlobal } from "../internal"
1
+ import { assign } from "./utils"
2
2
 
3
3
  // safely get iterator prototype if available
4
- const global = getGlobal()
5
- const maybeIteratorPrototype = global.Iterator?.prototype || {}
4
+ const maybeIteratorPrototype = (globalThis as any).Iterator?.prototype || {}
6
5
 
7
6
  export function makeIterable<T, TReturn = unknown>(
8
7
  iterator: Iterator<T>
9
8
  ): IteratorObject<T, TReturn> {
10
9
  iterator[Symbol.iterator] = getSelf
11
- return Object.assign(Object.create(maybeIteratorPrototype), iterator)
10
+ return assign(Object.create(maybeIteratorPrototype), iterator)
12
11
  }
13
12
 
14
13
  function getSelf() {
@@ -1,4 +1,4 @@
1
- import { globalState, die } from "../internal"
1
+ import { globalState } from "../internal"
2
2
 
3
3
  // We shorten anything used > 5 times
4
4
  export const assign = Object.assign
@@ -17,28 +17,8 @@ export interface Lambda {
17
17
  name?: string
18
18
  }
19
19
 
20
- const hasProxy = typeof Proxy !== "undefined"
21
20
  const plainObjectString = Object.toString()
22
21
 
23
- export function assertProxies() {
24
- if (!hasProxy) {
25
- die(
26
- __DEV__
27
- ? "`Proxy` objects are not available in the current environment. Please configure MobX to enable a fallback implementation.`"
28
- : "Proxy not available"
29
- )
30
- }
31
- }
32
-
33
- export function warnAboutProxyRequirement(msg: string) {
34
- if (__DEV__ && globalState.verifyProxies) {
35
- die(
36
- "MobX is currently configured to be able to run in ES5 mode, but in ES5 MobX won't be able to " +
37
- msg
38
- )
39
- }
40
- }
41
-
42
22
  export function getNextId() {
43
23
  return ++globalState.mobxGuid
44
24
  }
@@ -90,7 +70,7 @@ export function isPlainObject(value: any) {
90
70
  if (proto == null) {
91
71
  return true
92
72
  }
93
- const protoConstructor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor
73
+ const protoConstructor = hasProp(proto, "constructor") && proto.constructor
94
74
  return (
95
75
  typeof protoConstructor === "function" && protoConstructor.toString() === plainObjectString
96
76
  )
@@ -164,17 +144,11 @@ export function isES6Set(thing: unknown): thing is Set<any> {
164
144
  return thing != null && Object.prototype.toString.call(thing) === "[object Set]"
165
145
  }
166
146
 
167
- const hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefined"
168
-
169
147
  /**
170
148
  * Returns the following: own enumerable keys and symbols.
171
149
  */
172
150
  export function getPlainObjectKeys(object: any) {
173
151
  const keys = Object.keys(object)
174
- // Not supported in IE, so there are not going to be symbol props anyway...
175
- if (!hasGetOwnPropertySymbols) {
176
- return keys
177
- }
178
152
  const symbols = Object.getOwnPropertySymbols(object)
179
153
  if (!symbols.length) {
180
154
  return keys
@@ -184,12 +158,7 @@ export function getPlainObjectKeys(object: any) {
184
158
 
185
159
  // From Immer utils
186
160
  // Returns all own keys, including non-enumerable and symbolic
187
- export const ownKeys: (target: any) => Array<string | symbol> =
188
- typeof Reflect !== "undefined" && Reflect.ownKeys
189
- ? Reflect.ownKeys
190
- : hasGetOwnPropertySymbols
191
- ? obj => Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj) as any)
192
- : /* istanbul ignore next */ Object.getOwnPropertyNames
161
+ export const ownKeys: (target: any) => Array<string | symbol> = Reflect.ownKeys
193
162
 
194
163
  export function stringifyKey(key: any): string {
195
164
  if (typeof key === "string") {
@@ -209,18 +178,7 @@ export function hasProp(target: Object, prop: PropertyKey): boolean {
209
178
  return objectPrototype.hasOwnProperty.call(target, prop)
210
179
  }
211
180
 
212
- // From Immer utils
213
- export const getOwnPropertyDescriptors =
214
- Object.getOwnPropertyDescriptors ||
215
- function getOwnPropertyDescriptors(target: any) {
216
- // Polyfill needed for Hermes and IE, see https://github.com/facebook/hermes/issues/274
217
- const res: any = {}
218
- // Note: without polyfill for ownKeys, symbols won't be picked up
219
- ownKeys(target).forEach(key => {
220
- res[key] = getDescriptor(target, key)
221
- })
222
- return res
223
- }
181
+ export const getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors
224
182
 
225
183
  export function getFlag(flags: number, mask: number) {
226
184
  return !!(flags & mask)
@@ -1,3 +0,0 @@
1
- export declare function trace(thing?: any, prop?: string, enterBreakPoint?: boolean): void;
2
- export declare function trace(thing?: any, enterBreakPoint?: boolean): void;
3
- export declare function trace(enterBreakPoint?: boolean): void;
@@ -1,14 +0,0 @@
1
- import { IEnhancer, IObservableArray } from "../internal";
2
- declare class StubArray {
3
- }
4
- export declare class LegacyObservableArray<T> extends StubArray {
5
- constructor(initialValues: T[] | undefined, enhancer: IEnhancer<T>, name?: string, owned?: boolean);
6
- concat(...arrays: T[][]): T[];
7
- get length(): number;
8
- set length(newLength: number);
9
- get [Symbol.toStringTag](): string;
10
- [Symbol.iterator](): IteratorObject<any, unknown, unknown>;
11
- }
12
- export declare function reserveArrayBuffer(max: number): void;
13
- export declare function createLegacyArray<T>(initialValues: T[] | undefined, enhancer: IEnhancer<T>, name?: string): IObservableArray<T>;
14
- export {};
@@ -1 +0,0 @@
1
- export declare function getGlobal(): any;
package/src/api/trace.ts DELETED
@@ -1,35 +0,0 @@
1
- import { TraceMode, die, getAtom, globalState } from "../internal"
2
-
3
- export function trace(thing?: any, prop?: string, enterBreakPoint?: boolean): void
4
- export function trace(thing?: any, enterBreakPoint?: boolean): void
5
- export function trace(enterBreakPoint?: boolean): void
6
- export function trace(...args: any[]): void {
7
- if (!__DEV__) {
8
- return
9
- }
10
- let enterBreakPoint = false
11
- if (typeof args[args.length - 1] === "boolean") {
12
- enterBreakPoint = args.pop()
13
- }
14
- const derivation = getAtomFromArgs(args)
15
- if (!derivation) {
16
- return die(
17
- `'trace(break?)' can only be used inside a tracked computed value or a Reaction. Consider passing in the computed value or reaction explicitly`
18
- )
19
- }
20
- if (derivation.isTracing_ === TraceMode.NONE) {
21
- console.log(`[mobx.trace] '${derivation.name_}' tracing enabled`)
22
- }
23
- derivation.isTracing_ = enterBreakPoint ? TraceMode.BREAK : TraceMode.LOG
24
- }
25
-
26
- function getAtomFromArgs(args): any {
27
- switch (args.length) {
28
- case 0:
29
- return globalState.trackingDerivation
30
- case 1:
31
- return getAtom(args[0])
32
- case 2:
33
- return getAtom(args[0], args[1])
34
- }
35
- }