mobx 6.1.8 → 6.9.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 (91) hide show
  1. package/CHANGELOG.md +224 -7
  2. package/README.md +54 -52
  3. package/dist/api/annotation.d.ts +6 -12
  4. package/dist/api/autorun.d.ts +4 -4
  5. package/dist/api/flow.d.ts +1 -0
  6. package/dist/api/intercept.d.ts +5 -5
  7. package/dist/api/object-api.d.ts +2 -0
  8. package/dist/api/observable.d.ts +5 -1
  9. package/dist/api/observe.d.ts +4 -4
  10. package/dist/api/tojs.d.ts +4 -1
  11. package/dist/api/when.d.ts +8 -0
  12. package/dist/core/atom.d.ts +1 -1
  13. package/dist/core/computedvalue.d.ts +0 -1
  14. package/dist/core/globalstate.d.ts +4 -0
  15. package/dist/core/reaction.d.ts +2 -2
  16. package/dist/errors.d.ts +4 -2
  17. package/dist/internal.d.ts +1 -0
  18. package/dist/mobx.cjs.development.js +1477 -1719
  19. package/dist/mobx.cjs.development.js.map +1 -1
  20. package/dist/mobx.cjs.production.min.js +1 -1
  21. package/dist/mobx.cjs.production.min.js.map +1 -1
  22. package/dist/mobx.d.ts +1 -1
  23. package/dist/mobx.esm.development.js +1475 -1720
  24. package/dist/mobx.esm.development.js.map +1 -1
  25. package/dist/mobx.esm.js +1492 -1726
  26. package/dist/mobx.esm.js.map +1 -1
  27. package/dist/mobx.esm.production.min.js +1 -1
  28. package/dist/mobx.esm.production.min.js.map +1 -1
  29. package/dist/mobx.umd.development.js +1477 -1719
  30. package/dist/mobx.umd.development.js.map +1 -1
  31. package/dist/mobx.umd.production.min.js +1 -1
  32. package/dist/mobx.umd.production.min.js.map +1 -1
  33. package/dist/types/actionannotation.d.ts +7 -1
  34. package/dist/types/autoannotation.d.ts +3 -0
  35. package/dist/types/observablemap.d.ts +5 -4
  36. package/dist/types/observableobject.d.ts +6 -9
  37. package/dist/types/observableset.d.ts +4 -4
  38. package/dist/types/observablevalue.d.ts +3 -5
  39. package/dist/utils/utils.d.ts +4 -4
  40. package/package.json +1 -1
  41. package/src/api/action.ts +8 -3
  42. package/src/api/annotation.ts +14 -44
  43. package/src/api/autorun.ts +38 -17
  44. package/src/api/computed.ts +5 -2
  45. package/src/api/configure.ts +6 -2
  46. package/src/api/decorators.ts +1 -1
  47. package/src/api/extendobservable.ts +12 -6
  48. package/src/api/extras.ts +4 -2
  49. package/src/api/flow.ts +17 -5
  50. package/src/api/intercept-read.ts +4 -2
  51. package/src/api/intercept.ts +10 -7
  52. package/src/api/iscomputed.ts +14 -8
  53. package/src/api/isobservable.ts +10 -4
  54. package/src/api/makeObservable.ts +35 -36
  55. package/src/api/object-api.ts +42 -14
  56. package/src/api/observable.ts +39 -25
  57. package/src/api/observe.ts +9 -6
  58. package/src/api/tojs.ts +20 -10
  59. package/src/api/trace.ts +6 -2
  60. package/src/api/when.ts +34 -9
  61. package/src/core/action.ts +11 -5
  62. package/src/core/atom.ts +9 -2
  63. package/src/core/computedvalue.ts +48 -27
  64. package/src/core/derivation.ts +34 -12
  65. package/src/core/globalstate.ts +25 -7
  66. package/src/core/observable.ts +23 -13
  67. package/src/core/reaction.ts +16 -7
  68. package/src/core/spy.ts +20 -7
  69. package/src/errors.ts +16 -3
  70. package/src/internal.ts +1 -0
  71. package/src/mobx.ts +6 -2
  72. package/src/types/actionannotation.ts +30 -52
  73. package/src/types/autoannotation.ts +107 -0
  74. package/src/types/computedannotation.ts +7 -37
  75. package/src/types/dynamicobject.ts +12 -6
  76. package/src/types/flowannotation.ts +40 -41
  77. package/src/types/intercept-utils.ts +9 -3
  78. package/src/types/legacyobservablearray.ts +26 -3
  79. package/src/types/listen-utils.ts +6 -2
  80. package/src/types/modifiers.ts +52 -16
  81. package/src/types/observableannotation.ts +7 -34
  82. package/src/types/observablearray.ts +106 -45
  83. package/src/types/observablemap.ts +71 -35
  84. package/src/types/observableobject.ts +88 -82
  85. package/src/types/observableset.ts +32 -13
  86. package/src/types/observablevalue.ts +16 -10
  87. package/src/types/overrideannotation.ts +4 -2
  88. package/src/types/type-utils.ts +34 -12
  89. package/src/utils/comparer.ts +5 -1
  90. package/src/utils/eq.ts +45 -15
  91. package/src/utils/utils.ts +39 -16
@@ -1,10 +1,18 @@
1
1
  import { IReactionDisposer, Lambda } from "../internal";
2
+ interface GenericAbortSignal {
3
+ readonly aborted: boolean;
4
+ onabort?: ((...args: any) => any) | null;
5
+ addEventListener?: (...args: any) => any;
6
+ removeEventListener?: (...args: any) => any;
7
+ }
2
8
  export interface IWhenOptions {
3
9
  name?: string;
4
10
  timeout?: number;
5
11
  onError?: (error: any) => void;
12
+ signal?: GenericAbortSignal;
6
13
  }
7
14
  export declare function when(predicate: () => boolean, opts?: IWhenOptions): Promise<void> & {
8
15
  cancel(): void;
9
16
  };
10
17
  export declare function when(predicate: () => boolean, effect: Lambda, opts?: IWhenOptions): IReactionDisposer;
18
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { IDerivationState_, IObservable, IDerivation, Lambda } from "../internal";
2
2
  export declare const $mobx: unique symbol;
3
3
  export interface IAtom extends IObservable {
4
- reportObserved(): any;
4
+ reportObserved(): boolean;
5
5
  reportChanged(): any;
6
6
  }
7
7
  export declare class Atom implements IAtom {
@@ -2,7 +2,6 @@ import { CaughtException, IDerivation, IDerivationState_, IEqualsComparer, IObse
2
2
  export interface IComputedValue<T> {
3
3
  get(): T;
4
4
  set(value: T): void;
5
- observe_(listener: (change: IComputedDidChange<T>) => void, fireImmediately?: boolean): Lambda;
6
5
  }
7
6
  export interface IComputedValueOptions<T> {
8
7
  get?: () => T;
@@ -101,6 +101,10 @@ export declare class MobXGlobals {
101
101
  * configurable: true
102
102
  */
103
103
  safeDescriptors: boolean;
104
+ /**
105
+ * Changes with each state update, used by useSyncExternalStore
106
+ */
107
+ stateVersion: number;
104
108
  }
105
109
  export declare let globalState: MobXGlobals;
106
110
  export declare function isolateGlobalState(): void;
@@ -29,7 +29,7 @@ export declare class Reaction implements IDerivation, IReactionPublic {
29
29
  name_: string;
30
30
  private onInvalidate_;
31
31
  private errorHandler_?;
32
- requiresObservable_: boolean;
32
+ requiresObservable_?: any;
33
33
  observing_: IObservable[];
34
34
  newObserving_: IObservable[];
35
35
  dependenciesState_: IDerivationState_;
@@ -41,7 +41,7 @@ export declare class Reaction implements IDerivation, IReactionPublic {
41
41
  isTrackPending_: boolean;
42
42
  isRunning_: boolean;
43
43
  isTracing_: TraceMode;
44
- constructor(name_: string, onInvalidate_: () => void, errorHandler_?: ((error: any, derivation: IDerivation) => void) | undefined, requiresObservable_?: boolean);
44
+ constructor(name_: string, onInvalidate_: () => void, errorHandler_?: ((error: any, derivation: IDerivation) => void) | undefined, requiresObservable_?: any);
45
45
  onBecomeStale_(): void;
46
46
  schedule_(): void;
47
47
  isScheduled(): boolean;
package/dist/errors.d.ts CHANGED
@@ -9,9 +9,9 @@ declare const niceErrors: {
9
9
  readonly 10: "'has()' can only be used on observable objects, arrays and maps";
10
10
  readonly 11: "'get()' can only be used on observable objects, arrays and maps";
11
11
  readonly 12: "Invalid annotation";
12
- readonly 13: "Dynamic observable objects cannot be frozen";
12
+ readonly 13: "Dynamic observable objects cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)";
13
13
  readonly 14: "Intercept handlers should return nothing or a change object";
14
- readonly 15: "Observable arrays cannot be frozen";
14
+ readonly 15: "Observable arrays cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)";
15
15
  readonly 16: "Modification exception: the internal structure of an observable array was changed.";
16
16
  readonly 17: (index: any, length: any) => string;
17
17
  readonly 18: "mobx.map requires Map polyfill for the current browser. Check babel-polyfill or core-js/es6/map.js";
@@ -34,6 +34,8 @@ declare const niceErrors: {
34
34
  readonly 35: "There are multiple, different versions of MobX active. Make sure MobX is loaded only once or use `configure({ isolateGlobalState: true })`";
35
35
  readonly 36: "isolateGlobalState should be called before MobX is running any reactions";
36
36
  readonly 37: (method: any) => string;
37
+ readonly 38: "'ownKeys()' can only be used on observable objects";
38
+ readonly 39: "'defineProperty()' can only be used on observable objects";
37
39
  };
38
40
  declare const errors: typeof niceErrors;
39
41
  export declare function die(error: string | keyof typeof errors, ...args: any[]): never;
@@ -10,6 +10,7 @@ export * from "./types/actionannotation";
10
10
  export * from "./types/flowannotation";
11
11
  export * from "./types/computedannotation";
12
12
  export * from "./types/observableannotation";
13
+ export * from "./types/autoannotation";
13
14
  export * from "./api/observable";
14
15
  export * from "./api/computed";
15
16
  export * from "./core/action";