mobx 6.16.1 → 7.0.1
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.
- package/CHANGELOG.md +86 -0
- package/README.md +9 -13
- package/dist/api/action.d.ts +6 -4
- package/dist/api/annotation.d.ts +0 -1
- package/dist/api/computed.d.ts +4 -7
- package/dist/api/configure.d.ts +0 -1
- package/dist/api/decoratorannotation.d.ts +3 -0
- package/dist/api/decorators.d.ts +0 -19
- package/dist/api/flow.d.ts +4 -5
- package/dist/api/makeObservable.d.ts +2 -3
- package/dist/api/observable.d.ts +9 -15
- package/dist/core/atom.d.ts +1 -4
- package/dist/core/computedvalue.d.ts +5 -33
- package/dist/core/derivation.d.ts +1 -7
- package/dist/core/globalstate.d.ts +7 -2
- package/dist/core/observable.d.ts +9 -1
- package/dist/core/reaction.d.ts +1 -9
- package/dist/errors.d.ts +6 -4
- package/dist/internal.d.ts +1 -4
- package/dist/mobx.cjs.development.js +1704 -2484
- package/dist/mobx.cjs.development.js.map +1 -1
- package/dist/mobx.cjs.production.min.js +1 -1
- package/dist/mobx.cjs.production.min.js.map +1 -1
- package/dist/mobx.d.ts +2 -2
- package/dist/mobx.esm.development.js +1693 -2483
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +1643 -2436
- package/dist/mobx.esm.js.map +1 -1
- package/dist/mobx.esm.production.min.js +1 -1
- package/dist/mobx.esm.production.min.js.map +1 -1
- package/dist/mobx.mjs +5308 -0
- package/dist/mobx.mjs.map +1 -0
- package/dist/mobx.umd.development.js +1707 -2487
- package/dist/mobx.umd.development.js.map +1 -1
- package/dist/mobx.umd.production.min.js +1 -1
- package/dist/mobx.umd.production.min.js.map +1 -1
- package/dist/types/actionannotation.d.ts +1 -0
- package/dist/types/computedannotation.d.ts +1 -0
- package/dist/types/decorator_fills.d.ts +2 -0
- package/dist/types/flowannotation.d.ts +1 -0
- package/dist/types/observableannotation.d.ts +5 -0
- package/dist/types/observablearray.d.ts +2 -5
- package/dist/types/observablemap.d.ts +1 -8
- package/dist/types/observableobject.d.ts +2 -13
- package/dist/types/observableset.d.ts +1 -3
- package/dist/types/observablevalue.d.ts +4 -6
- package/dist/types/overrideannotation.d.ts +1 -2
- package/dist/utils/comparer.d.ts +4 -11
- package/dist/utils/utils.d.ts +0 -2
- package/package.json +25 -15
- package/src/api/action.ts +27 -35
- package/src/api/annotation.ts +0 -1
- package/src/api/autorun.ts +2 -4
- package/src/api/computed.ts +21 -28
- package/src/api/configure.ts +1 -15
- package/src/api/decoratorannotation.ts +20 -0
- package/src/api/decorators.ts +1 -85
- package/src/api/extras.ts +1 -1
- package/src/api/flow.ts +26 -29
- package/src/api/intercept.ts +4 -3
- package/src/api/makeObservable.ts +45 -17
- package/src/api/object-api.ts +1 -1
- package/src/api/observable.ts +34 -67
- package/src/api/observe.ts +82 -3
- package/src/api/when.ts +4 -3
- package/src/core/action.ts +12 -5
- package/src/core/atom.ts +16 -14
- package/src/core/computedvalue.ts +36 -69
- package/src/core/derivation.ts +16 -15
- package/src/core/globalstate.ts +16 -13
- package/src/core/observable.ts +65 -73
- package/src/core/reaction.ts +19 -25
- package/src/core/spy.ts +3 -3
- package/src/errors.ts +23 -12
- package/src/internal.ts +1 -4
- package/src/mobx.ts +21 -10
- package/src/types/actionannotation.ts +5 -9
- package/src/types/autoannotation.ts +8 -11
- package/src/types/computedannotation.ts +13 -11
- package/src/types/decorator_fills.ts +4 -0
- package/src/types/dynamicobject.ts +0 -29
- package/src/types/flowannotation.ts +7 -4
- package/src/types/modifiers.ts +5 -0
- package/src/types/observableannotation.ts +6 -7
- package/src/types/observablearray.ts +8 -61
- package/src/types/observablemap.ts +4 -29
- package/src/types/observableobject.ts +5 -70
- package/src/types/observableset.ts +9 -52
- package/src/types/observablevalue.ts +7 -29
- package/src/types/overrideannotation.ts +7 -22
- package/src/types/type-utils.ts +4 -2
- package/src/utils/comparer.ts +4 -17
- package/src/utils/iterable.ts +3 -4
- package/src/utils/utils.ts +4 -46
- package/dist/api/trace.d.ts +0 -3
- package/dist/types/legacyobservablearray.d.ts +0 -14
- package/dist/utils/global.d.ts +0 -1
- package/src/api/trace.ts +0 -35
- package/src/types/legacyobservablearray.ts +0 -155
- package/src/utils/global.ts +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,91 @@
|
|
|
1
1
|
# mobx
|
|
2
2
|
|
|
3
|
+
## 7.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`9444c624b957b489875e1c6b45deb290034ce4e9`](https://github.com/mobxjs/mobx/commit/9444c624b957b489875e1c6b45deb290034ce4e9) [#4694](https://github.com/mobxjs/mobx/pull/4694) Thanks [@mrpmohiburrahman](https://github.com/mrpmohiburrahman)! - fix: `onBecomeObserved` is now called for the dependencies of a computed that becomes observed while serving a cached value. Previously, observation only cascaded when the newly observed computed also happened to recompute, so an observable with a live observer chain up to a running reaction could still report itself as unobserved and never fire its hook.
|
|
8
|
+
|
|
9
|
+
- [`53bb83fdf455a4e606bb721ea10040ded7c57796`](https://github.com/mobxjs/mobx/commit/53bb83fdf455a4e606bb721ea10040ded7c57796) [#4683](https://github.com/mobxjs/mobx/pull/4683) Thanks [@gesposito](https://github.com/gesposito)! - perf: fast-path primitives in `deepEnhancer`. Writing a primitive into a deep observable no longer runs the observable/array/plain-object/Map/Set/function type checks; primitives can never be made observable, so they are returned immediately. Creating an observable array of primitives is ~4x faster, and observable Set/Map writes are ~20-25% faster in the perf suite.
|
|
10
|
+
|
|
11
|
+
- [`030498d6b2bfe4cc27340fed8c706177cb3b28e1`](https://github.com/mobxjs/mobx/commit/030498d6b2bfe4cc27340fed8c706177cb3b28e1) [#4684](https://github.com/mobxjs/mobx/pull/4684) Thanks [@a-y-ibrahim](https://github.com/a-y-ibrahim)! - Fix a stack overflow ("Maximum call stack size exceeded") that could occur when an `onBecomeUnobserved` handler disposes a `Reaction`. Disposing a `Reaction` re-enters `endBatch()`, which used to recurse into the same `pendingUnobservations` drain loop instead of letting the already-running outer loop pick up the newly queued items, causing unbounded stack depth for long enough chains.
|
|
12
|
+
|
|
13
|
+
- [`a9086076b9ead1a9c933215bffaa9b57d44f6829`](https://github.com/mobxjs/mobx/commit/a9086076b9ead1a9c933215bffaa9b57d44f6829) [#4681](https://github.com/mobxjs/mobx/pull/4681) Thanks [@spokodev](https://github.com/spokodev)! - Fix ObservableSet union, intersection and symmetricDifference to return results in receiver order, matching native Set, when the argument is a plain Set.
|
|
14
|
+
|
|
15
|
+
- [`c65a4e14cf48b42cb792dc4c64edbcf56234b32d`](https://github.com/mobxjs/mobx/commit/c65a4e14cf48b42cb792dc4c64edbcf56234b32d) [#4682](https://github.com/mobxjs/mobx/pull/4682) Thanks [@gesposito](https://github.com/gesposito)! - perf: lazily allocate the internal `observers_` Set. Atoms and computed values no longer allocate an empty `Set` upfront; it is created on first observer instead. Most atoms in large stores are never observed, so this saves roughly 160 bytes per unobserved atom (e.g. ~35% lower heap usage when hydrating 50k instances with 10 observable fields each).
|
|
16
|
+
|
|
17
|
+
## 7.0.0
|
|
18
|
+
|
|
19
|
+
### Major Changes
|
|
20
|
+
|
|
21
|
+
- [`1926c69f53168619d688f348aa587e8f3ae579ae`](https://github.com/mobxjs/mobx/commit/1926c69f53168619d688f348aa587e8f3ae579ae) [#4671](https://github.com/mobxjs/mobx/pull/4671) Thanks [@kubk](https://github.com/kubk)! - Release MobX 7, mobx-react-lite 5, and mobx-react 10.
|
|
22
|
+
|
|
23
|
+
Bundle sizes are down: ESM prod 17.02 KiB gzip -> 13.96 KiB gzip; a minimal tree-shaken example is 10.32 KiB gzip now.
|
|
24
|
+
|
|
25
|
+
It removes long-deprecated compatibility paths and keeps the React bindings split between `mobx-react-lite` for function components and `mobx-react` for class-component support.
|
|
26
|
+
|
|
27
|
+
## MobX 7
|
|
28
|
+
|
|
29
|
+
MobX 7 is a cleanup release focused on the modern runtime and decorator model.
|
|
30
|
+
|
|
31
|
+
- MobX now always uses Proxy-backed observable objects and arrays. The ES5/non-proxy fallback has been removed.
|
|
32
|
+
- `configure({ useProxies: ... })` is no longer supported.
|
|
33
|
+
- `{ proxy: false }` options for `observable`, `observable.object`, and `observable.array` are no longer supported.
|
|
34
|
+
- Legacy decorators are no longer supported.
|
|
35
|
+
- Namespaced annotation and comparer properties now use named exports to reduce bundle size:
|
|
36
|
+
|
|
37
|
+
| Removed API | Replacement |
|
|
38
|
+
| --------------------- | ------------------- |
|
|
39
|
+
| `observable.ref` | `observableRef` |
|
|
40
|
+
| `observable.shallow` | `observableShallow` |
|
|
41
|
+
| `observable.deep` | `observableDeep` |
|
|
42
|
+
| `observable.struct` | `observableStruct` |
|
|
43
|
+
| `computed.struct` | `computedStruct` |
|
|
44
|
+
| `action.bound` | `actionBound` |
|
|
45
|
+
| `flow.bound` | `flowBound` |
|
|
46
|
+
| `comparer.identity` | `compareIdentity` |
|
|
47
|
+
| `comparer.default` | `compareDefault` |
|
|
48
|
+
| `comparer.structural` | `compareStructural` |
|
|
49
|
+
| `comparer.shallow` | `compareShallow` |
|
|
50
|
+
|
|
51
|
+
- The public `trace` API and its related runtime support have been removed. Use `toJS`, `getDependencyTree`, `getObserverTree`, `spy` or `mobx-log` package for debugging.
|
|
52
|
+
|
|
53
|
+
## mobx-react-lite 5 and mobx-react 10
|
|
54
|
+
|
|
55
|
+
mobx-react-lite 5 and mobx-react 10 require MobX 7 and React 18 or later.
|
|
56
|
+
|
|
57
|
+
`mobx-react-lite` remains the function-component package. `mobx-react` remains a thin wrapper around `mobx-react-lite` that adds class component and Stage 3 `@observer` class decorator support.
|
|
58
|
+
|
|
59
|
+
- Keep function-component imports on `mobx-react-lite` if you do not need class component support.
|
|
60
|
+
- Use `mobx-react` when you need class components or `@observer` class decorators.
|
|
61
|
+
- `mobx-react-lite` supports function components and `forwardRef`; `mobx-react` delegates function components to `mobx-react-lite` and handles classes itself.
|
|
62
|
+
- Remove React batching imports, including the stale React Native batching deep import. React 18+ renderers handle batching.
|
|
63
|
+
|
|
64
|
+
The recommended public React binding surface for both packages is:
|
|
65
|
+
|
|
66
|
+
- `observer`
|
|
67
|
+
- `Observer`
|
|
68
|
+
- `useLocalObservable`
|
|
69
|
+
- `enableStaticRendering`
|
|
70
|
+
- `isUsingStaticRendering`
|
|
71
|
+
|
|
72
|
+
The following APIs have been removed from the React binding packages:
|
|
73
|
+
|
|
74
|
+
- `Provider`, `inject`, and `MobXProviderContext`; use `React.createContext` directly.
|
|
75
|
+
- `disposeOnUnmount`; dispose reactions in `componentWillUnmount` or return cleanup functions from `useEffect`.
|
|
76
|
+
- `PropTypes`; use TypeScript or the regular `prop-types` package.
|
|
77
|
+
- `useObserver`; wrap components with `observer` or use `<Observer>`.
|
|
78
|
+
- `useLocalStore`; use `useLocalObservable`.
|
|
79
|
+
- `useAsObservableSource`; synchronize values from props into local observable state explicitly.
|
|
80
|
+
- `useStaticRendering`; use `enableStaticRendering`.
|
|
81
|
+
- `observerBatching`, `isObserverBatched`, `batchingForReactDom`, `batchingOptOut`, and `batchingForReactNative`; remove these imports because React 18+ renderers handle batching.
|
|
82
|
+
- Deprecated `observer(fn, { forwardRef: true })`; pass an already-created `React.forwardRef(...)` component to `observer` instead.
|
|
83
|
+
- Legacy function-component `contextTypes` handling.
|
|
84
|
+
|
|
85
|
+
### Patch Changes
|
|
86
|
+
|
|
87
|
+
- [`979d267d569734dc3cb969ed1880ed68bb79f1b5`](https://github.com/mobxjs/mobx/commit/979d267d569734dc3cb969ed1880ed68bb79f1b5) [#4677](https://github.com/mobxjs/mobx/pull/4677) Thanks [@kubk](https://github.com/kubk)! - Shorten minified error URL to reduce production bundle size.
|
|
88
|
+
|
|
3
89
|
## 6.16.1
|
|
4
90
|
|
|
5
91
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -114,19 +114,15 @@ import { makeAutoObservable } from "mobx"
|
|
|
114
114
|
import { observer } from "mobx-react-lite"
|
|
115
115
|
|
|
116
116
|
// Model the application state.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const myTimer = createTimer()
|
|
117
|
+
const myTimer = makeAutoObservable({
|
|
118
|
+
secondsPassed: 0,
|
|
119
|
+
increase() {
|
|
120
|
+
this.secondsPassed += 1
|
|
121
|
+
},
|
|
122
|
+
reset() {
|
|
123
|
+
this.secondsPassed = 0
|
|
124
|
+
}
|
|
125
|
+
})
|
|
130
126
|
|
|
131
127
|
// Build a "user interface" that uses the observable state.
|
|
132
128
|
const TimerView = observer(({ timer }) => (
|
package/dist/api/action.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { Annotation } from "../internal";
|
|
2
|
-
import
|
|
2
|
+
import { type DecoratorAnnotation } from "./decoratorannotation";
|
|
3
|
+
import type { ClassMethodAndFieldDecorator } from "../types/decorator_fills";
|
|
3
4
|
export declare const ACTION = "action";
|
|
4
5
|
export declare const ACTION_BOUND = "action.bound";
|
|
5
6
|
export declare const AUTOACTION = "autoAction";
|
|
6
7
|
export declare const AUTOACTION_BOUND = "autoAction.bound";
|
|
7
|
-
export interface IActionFactory extends Annotation,
|
|
8
|
+
export interface IActionFactory extends Annotation, ClassMethodAndFieldDecorator {
|
|
8
9
|
<T extends Function | undefined | null>(fn: T): T;
|
|
9
10
|
<T extends Function | undefined | null>(name: string, fn: T): T;
|
|
10
|
-
(customName: string):
|
|
11
|
-
bound: Annotation & PropertyDecorator & ClassMethodDecorator & ClassFieldDecorator;
|
|
11
|
+
(customName: string): DecoratorAnnotation<ClassMethodAndFieldDecorator>;
|
|
12
12
|
}
|
|
13
13
|
export declare const action: IActionFactory;
|
|
14
14
|
export declare const autoAction: IActionFactory;
|
|
15
|
+
export declare const actionBound: DecoratorAnnotation<ClassMethodAndFieldDecorator>;
|
|
16
|
+
export declare const autoActionBound: DecoratorAnnotation<ClassMethodAndFieldDecorator>;
|
|
15
17
|
export declare function runInAction<T>(fn: () => T): T;
|
|
16
18
|
export declare function isAction(thing: any): boolean;
|
package/dist/api/annotation.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export type Annotation = {
|
|
|
8
8
|
annotationType_: string;
|
|
9
9
|
make_(adm: ObservableObjectAdministration, key: PropertyKey, descriptor: PropertyDescriptor, source: object): MakeResult;
|
|
10
10
|
extend_(adm: ObservableObjectAdministration, key: PropertyKey, descriptor: PropertyDescriptor, proxyTrap: boolean): boolean | null;
|
|
11
|
-
decorate_20223_(value: any, context: DecoratorContext): any;
|
|
12
11
|
options_?: any;
|
|
13
12
|
};
|
|
14
13
|
export type AnnotationMapEntry = Annotation | true | false;
|
package/dist/api/computed.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { IComputedValueOptions, Annotation, IComputedValue } from "../internal";
|
|
2
|
+
import { type DecoratorAnnotation } from "./decoratorannotation";
|
|
2
3
|
import type { ClassGetterDecorator } from "../types/decorator_fills";
|
|
3
4
|
export declare const COMPUTED = "computed";
|
|
4
5
|
export declare const COMPUTED_STRUCT = "computed.struct";
|
|
5
|
-
export interface IComputedFactory extends Annotation,
|
|
6
|
-
<T>(options: IComputedValueOptions<T>):
|
|
6
|
+
export interface IComputedFactory extends Annotation, ClassGetterDecorator {
|
|
7
|
+
<T>(options: IComputedValueOptions<T>): DecoratorAnnotation<ClassGetterDecorator>;
|
|
7
8
|
<T>(func: () => T, options?: IComputedValueOptions<T>): IComputedValue<T>;
|
|
8
|
-
struct: Annotation & PropertyDecorator & ClassGetterDecorator;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
* Decorator for class properties: @computed get value() { return expr; }.
|
|
12
|
-
* For legacy purposes also invokable as ES5 observable created: `computed(() => expr)`;
|
|
13
|
-
*/
|
|
10
|
+
export declare const computedStruct: DecoratorAnnotation<ClassGetterDecorator>;
|
|
14
11
|
export declare const computed: IComputedFactory;
|
package/dist/api/configure.d.ts
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Annotation } from "./annotation";
|
|
2
|
+
export type DecoratorAnnotation<Decorator extends (...args: any[]) => any> = Annotation & Decorator;
|
|
3
|
+
export declare function createDecoratorAnnotation<Decorator extends (...args: any[]) => any>(annotation: Annotation, decorate: (annotation: Annotation, value: any, context: any) => any): DecoratorAnnotation<Decorator>;
|
package/dist/api/decorators.d.ts
CHANGED
|
@@ -1,20 +1 @@
|
|
|
1
|
-
import { Annotation, AnnotationsMap } from "../internal";
|
|
2
|
-
import type { Decorator } from "../types/decorator_fills";
|
|
3
|
-
export declare const storedAnnotationsSymbol: unique symbol;
|
|
4
|
-
/**
|
|
5
|
-
* Creates a function that acts as
|
|
6
|
-
* - decorator
|
|
7
|
-
* - annotation object
|
|
8
|
-
*/
|
|
9
|
-
export declare function createDecoratorAnnotation<D extends Decorator = Decorator>(annotation: Annotation): PropertyDecorator & Annotation & D;
|
|
10
|
-
/**
|
|
11
|
-
* Stores annotation to prototype,
|
|
12
|
-
* so it can be inspected later by `makeObservable` called from constructor
|
|
13
|
-
*/
|
|
14
|
-
export declare function storeAnnotation(prototype: any, key: PropertyKey, annotation: Annotation): void;
|
|
15
|
-
/**
|
|
16
|
-
* Collects annotations from prototypes and stores them on target (instance)
|
|
17
|
-
*/
|
|
18
|
-
export declare function collectStoredAnnotations(target: any): AnnotationsMap<any, any>;
|
|
19
|
-
export declare function is20223Decorator(context: any): context is DecoratorContext;
|
|
20
1
|
export declare function assert20223DecoratorType(context: DecoratorContext, types: DecoratorContext["kind"][]): void;
|
package/dist/api/flow.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Annotation } from "../internal";
|
|
2
|
+
import { type DecoratorAnnotation } from "./decoratorannotation";
|
|
2
3
|
import type { ClassMethodDecorator } from "../types/decorator_fills";
|
|
3
4
|
export declare const FLOW = "flow";
|
|
4
5
|
export declare class FlowCancellationError extends Error {
|
|
@@ -9,13 +10,11 @@ export declare function isFlowCancellationError(error: Error): error is FlowCanc
|
|
|
9
10
|
export type CancellablePromise<T> = Promise<T> & {
|
|
10
11
|
cancel(): void;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<This, Value extends FlowGenerator>(value: Value, context: ClassMethodDecoratorContext<This, Value>): Value | void;
|
|
15
|
-
<R, Args extends any[]>(generator: (...args: Args) => Generator<any, R, any> | AsyncGenerator<any, R, any>): (...args: Args) => CancellablePromise<R>;
|
|
16
|
-
bound: Annotation & PropertyDecorator & ClassMethodDecorator;
|
|
13
|
+
interface Flow extends Annotation, ClassMethodDecorator {
|
|
14
|
+
<R, Args extends any[]>(generator: (...args: Args) => Generator<any, R, any> | AsyncGenerator<any, R, any>, context?: never): (...args: Args) => CancellablePromise<R>;
|
|
17
15
|
}
|
|
18
16
|
export declare const flow: Flow;
|
|
17
|
+
export declare const flowBound: DecoratorAnnotation<ClassMethodDecorator>;
|
|
19
18
|
export declare function flowResult<T>(result: T): T extends Generator<any, infer R, any> ? CancellablePromise<R> : T extends CancellablePromise<any> ? T : never;
|
|
20
19
|
export declare function isFlow(fn: any): boolean;
|
|
21
20
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AnnotationsMap, CreateObservableOptions } from "../internal";
|
|
2
2
|
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function makeAutoObservable<T extends object, AdditionalKeys extends PropertyKey = never>(target: T, overrides?: AnnotationsMap<T, NoInfer<AdditionalKeys>>, options?: MakeObservableOptions): T;
|
|
3
|
+
export declare function makeObservable<T extends object, AdditionalKeys extends PropertyKey = never>(target: T, annotations: AnnotationsMap<T, NoInfer<AdditionalKeys>>, options?: CreateObservableOptions): T;
|
|
4
|
+
export declare function makeAutoObservable<T extends object, AdditionalKeys extends PropertyKey = never>(target: T, overrides?: AnnotationsMap<T, NoInfer<AdditionalKeys>>, options?: CreateObservableOptions): T;
|
|
6
5
|
export {};
|
package/dist/api/observable.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IEnhancer, IEqualsComparer, IObservableArray, IMapEntries, IReadonlyMapEntries, IKeyValueMap, IObservableSetInitialValues, IObservableValue, ObservableMap, ObservableSet, Annotation, AnnotationsMap } from "../internal";
|
|
2
|
-
import
|
|
2
|
+
import { type DecoratorAnnotation } from "./decoratorannotation";
|
|
3
|
+
import type { ClassAccessorAndFieldDecorator } from "../types/decorator_fills";
|
|
3
4
|
export declare const OBSERVABLE = "observable";
|
|
4
5
|
export declare const OBSERVABLE_REF = "observable.ref";
|
|
5
6
|
export declare const OBSERVABLE_SHALLOW = "observable.shallow";
|
|
@@ -9,7 +10,6 @@ export type CreateObservableOptions = {
|
|
|
9
10
|
equals?: IEqualsComparer<any>;
|
|
10
11
|
deep?: boolean;
|
|
11
12
|
defaultDecorator?: Annotation;
|
|
12
|
-
proxy?: boolean;
|
|
13
13
|
autoBind?: boolean;
|
|
14
14
|
};
|
|
15
15
|
export declare const defaultCreateObservableOptions: CreateObservableOptions;
|
|
@@ -29,25 +29,19 @@ export interface IObservableMapFactory {
|
|
|
29
29
|
<K, V>(initialValues?: Map<K, V>, options?: CreateObservableOptions): ObservableMap<K, V>;
|
|
30
30
|
<K = any, V = any>(initialValues: undefined, options?: CreateObservableOptions): ObservableMap<K, V>;
|
|
31
31
|
}
|
|
32
|
-
export interface IObservableFactory extends Annotation,
|
|
32
|
+
export interface IObservableFactory extends Annotation, ClassAccessorAndFieldDecorator {
|
|
33
33
|
<T = any>(value: T[], options?: CreateObservableOptions): IObservableArray<T>;
|
|
34
34
|
<T = any>(value: Set<T>, options?: CreateObservableOptions): ObservableSet<T>;
|
|
35
35
|
<K = any, V = any>(value: Map<K, V>, options?: CreateObservableOptions): ObservableMap<K, V>;
|
|
36
|
-
<T extends object>(value: T,
|
|
36
|
+
<T extends object>(value: T, annotations?: AnnotationsMap<T, never>, options?: CreateObservableOptions): T;
|
|
37
37
|
box: IObservableValueFactory;
|
|
38
38
|
array: <T = any>(initialValues?: T[], options?: CreateObservableOptions) => IObservableArray<T>;
|
|
39
39
|
set: <T = any>(initialValues?: IObservableSetInitialValues<T>, options?: CreateObservableOptions) => ObservableSet<T>;
|
|
40
40
|
map: IObservableMapFactory;
|
|
41
|
-
object: <T = any>(props: T,
|
|
42
|
-
/**
|
|
43
|
-
* Decorator that creates an observable that only observes the references, but doesn't try to turn the assigned value into an observable.ts.
|
|
44
|
-
*/
|
|
45
|
-
ref: Annotation & PropertyDecorator & ClassAccessorDecorator & ClassFieldDecorator;
|
|
46
|
-
/**
|
|
47
|
-
* Decorator that creates an observable converts its value (objects, maps or arrays) into a shallow observable structure
|
|
48
|
-
*/
|
|
49
|
-
shallow: Annotation & PropertyDecorator & ClassAccessorDecorator & ClassFieldDecorator;
|
|
50
|
-
deep: Annotation & PropertyDecorator & ClassAccessorDecorator & ClassFieldDecorator;
|
|
51
|
-
struct: Annotation & PropertyDecorator & ClassAccessorDecorator & ClassFieldDecorator;
|
|
41
|
+
object: <T = any>(props: T, annotations?: AnnotationsMap<T, never>, options?: CreateObservableOptions) => T;
|
|
52
42
|
}
|
|
43
|
+
export declare const observableRef: DecoratorAnnotation<ClassAccessorAndFieldDecorator>;
|
|
44
|
+
export declare const observableShallow: DecoratorAnnotation<ClassAccessorAndFieldDecorator>;
|
|
45
|
+
export declare const observableDeep: DecoratorAnnotation<ClassAccessorAndFieldDecorator>;
|
|
46
|
+
export declare const observableStruct: DecoratorAnnotation<ClassAccessorAndFieldDecorator>;
|
|
53
47
|
export declare var observable: IObservableFactory;
|
package/dist/core/atom.d.ts
CHANGED
|
@@ -6,11 +6,8 @@ export interface IAtom extends IObservable {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class Atom implements IAtom {
|
|
8
8
|
name_: string;
|
|
9
|
-
private static readonly isBeingObservedMask_;
|
|
10
|
-
private static readonly isPendingUnobservationMask_;
|
|
11
|
-
private static readonly diffValueMask_;
|
|
12
9
|
private flags_;
|
|
13
|
-
observers_: Set<IDerivation
|
|
10
|
+
observers_: Set<IDerivation> | null;
|
|
14
11
|
lastAccessedBy_: number;
|
|
15
12
|
lowestObserverState_: IDerivationState_;
|
|
16
13
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CaughtException, IDerivation, IDerivationState_, IEqualsComparer, IObservable, Lambda
|
|
1
|
+
import { CaughtException, IDerivation, IDerivationState_, IEqualsComparer, IObservable, Lambda } from "../internal";
|
|
2
2
|
export interface IComputedValue<T> {
|
|
3
3
|
get(): T;
|
|
4
4
|
set(value: T): void;
|
|
@@ -20,30 +20,11 @@ export type IComputedDidChange<T = any> = {
|
|
|
20
20
|
newValue: T;
|
|
21
21
|
oldValue: T | undefined;
|
|
22
22
|
};
|
|
23
|
-
/**
|
|
24
|
-
* A node in the state dependency root that observes other nodes, and can be observed itself.
|
|
25
|
-
*
|
|
26
|
-
* ComputedValue will remember the result of the computation for the duration of the batch, or
|
|
27
|
-
* while being observed.
|
|
28
|
-
*
|
|
29
|
-
* During this time it will recompute only when one of its direct dependencies changed,
|
|
30
|
-
* but only when it is being accessed with `ComputedValue.get()`.
|
|
31
|
-
*
|
|
32
|
-
* Implementation description:
|
|
33
|
-
* 1. First time it's being accessed it will compute and remember result
|
|
34
|
-
* give back remembered result until 2. happens
|
|
35
|
-
* 2. First time any deep dependency change, propagate POSSIBLY_STALE to all observers, wait for 3.
|
|
36
|
-
* 3. When it's being accessed, recompute if any shallow dependency changed.
|
|
37
|
-
* if result changed: propagate STALE to all observers, that were POSSIBLY_STALE from the last step.
|
|
38
|
-
* go to step 2. either way
|
|
39
|
-
*
|
|
40
|
-
* If at any point it's outside batch and it isn't observed: reset everything and go to 1.
|
|
41
|
-
*/
|
|
42
23
|
export declare class ComputedValue<T> implements IObservable, IComputedValue<T>, IDerivation {
|
|
43
24
|
dependenciesState_: IDerivationState_;
|
|
44
25
|
observing_: IObservable[];
|
|
45
26
|
newObserving_: null;
|
|
46
|
-
observers_: Set<IDerivation
|
|
27
|
+
observers_: Set<IDerivation> | null;
|
|
47
28
|
runId_: number;
|
|
48
29
|
lastAccessedBy_: number;
|
|
49
30
|
lowestObserverState_: IDerivationState_;
|
|
@@ -51,15 +32,9 @@ export declare class ComputedValue<T> implements IObservable, IComputedValue<T>,
|
|
|
51
32
|
protected value_: T | undefined | CaughtException;
|
|
52
33
|
name_: string;
|
|
53
34
|
triggeredBy_?: string;
|
|
54
|
-
private static readonly isComputingMask_;
|
|
55
|
-
private static readonly isRunningSetterMask_;
|
|
56
|
-
private static readonly isBeingObservedMask_;
|
|
57
|
-
private static readonly isPendingUnobservationMask_;
|
|
58
|
-
private static readonly diffValueMask_;
|
|
59
35
|
private flags_;
|
|
60
36
|
derivation: () => T;
|
|
61
37
|
setter_?: (value: T) => void;
|
|
62
|
-
isTracing_: TraceMode;
|
|
63
38
|
scope_: Object | undefined;
|
|
64
39
|
private equals_;
|
|
65
40
|
private requiresReaction_;
|
|
@@ -69,11 +44,9 @@ export declare class ComputedValue<T> implements IObservable, IComputedValue<T>,
|
|
|
69
44
|
*
|
|
70
45
|
* The `name` property is for debug purposes only.
|
|
71
46
|
*
|
|
72
|
-
* The `equals` property specifies the comparer function
|
|
73
|
-
* value differs from the previous value.
|
|
74
|
-
*
|
|
75
|
-
* Structural comparison can be convenient if you always produce a new aggregated object and
|
|
76
|
-
* don't want to notify observers if it is structurally the same.
|
|
47
|
+
* The `equals` property specifies the comparer function used to determine if a newly produced
|
|
48
|
+
* value differs from the previous value. Structural comparison can be convenient if you always
|
|
49
|
+
* produce a new aggregated object and don't want to notify observers if it is structurally the same.
|
|
77
50
|
* This is useful for working with vectors, mouse coordinates etc.
|
|
78
51
|
*/
|
|
79
52
|
constructor(options: IComputedValueOptions<T>);
|
|
@@ -101,7 +74,6 @@ export declare class ComputedValue<T> implements IObservable, IComputedValue<T>,
|
|
|
101
74
|
trackAndCompute(): boolean;
|
|
102
75
|
computeValue_(track: boolean): T | CaughtException;
|
|
103
76
|
suspend_(): void;
|
|
104
|
-
observe_(listener: (change: IComputedDidChange<T>) => void, fireImmediately?: boolean): Lambda;
|
|
105
77
|
warnAboutUntrackedRead_(): void;
|
|
106
78
|
toString(): string;
|
|
107
79
|
valueOf(): T;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { IAtom, IDepTreeNode, IObservable } from "../internal";
|
|
2
|
-
export declare enum IDerivationState_ {
|
|
2
|
+
export declare const enum IDerivationState_ {
|
|
3
3
|
NOT_TRACKING_ = -1,
|
|
4
4
|
UP_TO_DATE_ = 0,
|
|
5
5
|
POSSIBLY_STALE_ = 1,
|
|
6
6
|
STALE_ = 2
|
|
7
7
|
}
|
|
8
|
-
export declare enum TraceMode {
|
|
9
|
-
NONE = 0,
|
|
10
|
-
LOG = 1,
|
|
11
|
-
BREAK = 2
|
|
12
|
-
}
|
|
13
8
|
/**
|
|
14
9
|
* A derivation is everything that can be derived from the state (all the atoms) in a pure manner.
|
|
15
10
|
* See https://medium.com/@mweststrate/becoming-fully-reactive-an-in-depth-explanation-of-mobservable-55995262a254#.xvbh6qd74
|
|
@@ -28,7 +23,6 @@ export interface IDerivation extends IDepTreeNode {
|
|
|
28
23
|
*/
|
|
29
24
|
unboundDepsCount_: number;
|
|
30
25
|
onBecomeStale_(): void;
|
|
31
|
-
isTracing_: TraceMode;
|
|
32
26
|
/**
|
|
33
27
|
* warn if the derivation has no dependencies after creation/update
|
|
34
28
|
*/
|
|
@@ -52,6 +52,13 @@ export declare class MobXGlobals {
|
|
|
52
52
|
* Are we currently processing reactions?
|
|
53
53
|
*/
|
|
54
54
|
isRunningReactions: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Are we currently draining pendingUnobservations in endBatch?
|
|
57
|
+
* An onBecomeUnobserved handler can dispose a Reaction, which calls
|
|
58
|
+
* startBatch/endBatch again; this guards against re-entering the same
|
|
59
|
+
* drain loop recursively (see endBatch in observable.ts).
|
|
60
|
+
*/
|
|
61
|
+
isRunningUnobservations: boolean;
|
|
55
62
|
/**
|
|
56
63
|
* Is it allowed to change observables at this point?
|
|
57
64
|
* In general, MobX doesn't allow that when running computations and React.render.
|
|
@@ -93,8 +100,6 @@ export declare class MobXGlobals {
|
|
|
93
100
|
observableRequiresReaction: boolean;
|
|
94
101
|
disableErrorBoundaries: boolean;
|
|
95
102
|
suppressReactionErrors: boolean;
|
|
96
|
-
useProxies: boolean;
|
|
97
|
-
verifyProxies: boolean;
|
|
98
103
|
/**
|
|
99
104
|
* False forces all object's descriptors to
|
|
100
105
|
* writable: true
|
|
@@ -14,7 +14,7 @@ export interface IObservable extends IDepTreeNode {
|
|
|
14
14
|
isBeingObserved: boolean;
|
|
15
15
|
lowestObserverState_: IDerivationState_;
|
|
16
16
|
isPendingUnobservation: boolean;
|
|
17
|
-
observers_: Set<IDerivation
|
|
17
|
+
observers_: Set<IDerivation> | null;
|
|
18
18
|
onBUO(): void;
|
|
19
19
|
onBO(): void;
|
|
20
20
|
onBUOL: Set<Lambda> | undefined;
|
|
@@ -32,6 +32,14 @@ export declare function queueForUnobservation(observable: IObservable): void;
|
|
|
32
32
|
*/
|
|
33
33
|
export declare function startBatch(): void;
|
|
34
34
|
export declare function endBatch(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Marks an observable as observed, cascading into the dependencies of a ComputedValue.
|
|
37
|
+
* Unobservation already cascades (`suspend_` -> `clearObserving`), observation normally
|
|
38
|
+
* only does so by accident: a newly observed computed usually recomputes and re-reports
|
|
39
|
+
* its dependencies. When it serves a cached value instead nothing re-reports them, so the
|
|
40
|
+
* transition has to be propagated by hand. See #4547.
|
|
41
|
+
*/
|
|
42
|
+
export declare function markObserved(observable: IObservable): void;
|
|
35
43
|
export declare function reportObserved(observable: IObservable): boolean;
|
|
36
44
|
/**
|
|
37
45
|
* NOTE: current propagation mechanism will in case of self reruning autoruns behave unexpectedly
|
package/dist/core/reaction.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $mobx, IDerivation, IDerivationState_, IObservable, Lambda,
|
|
1
|
+
import { $mobx, IDerivation, IDerivationState_, IObservable, Lambda, GenericAbortSignal } from "../internal";
|
|
2
2
|
/**
|
|
3
3
|
* Reactions are a special kind of derivations. Several things distinguishes them from normal reactive computations
|
|
4
4
|
*
|
|
@@ -19,7 +19,6 @@ import { $mobx, IDerivation, IDerivationState_, IObservable, Lambda, TraceMode,
|
|
|
19
19
|
*/
|
|
20
20
|
export interface IReactionPublic {
|
|
21
21
|
dispose(): void;
|
|
22
|
-
trace(enterBreakPoint?: boolean): void;
|
|
23
22
|
}
|
|
24
23
|
export interface IReactionDisposer {
|
|
25
24
|
(): void;
|
|
@@ -35,13 +34,7 @@ export declare class Reaction implements IDerivation, IReactionPublic {
|
|
|
35
34
|
dependenciesState_: IDerivationState_;
|
|
36
35
|
runId_: number;
|
|
37
36
|
unboundDepsCount_: number;
|
|
38
|
-
private static readonly isDisposedMask_;
|
|
39
|
-
private static readonly isScheduledMask_;
|
|
40
|
-
private static readonly isTrackPendingMask_;
|
|
41
|
-
private static readonly isRunningMask_;
|
|
42
|
-
private static readonly diffValueMask_;
|
|
43
37
|
private flags_;
|
|
44
|
-
isTracing_: TraceMode;
|
|
45
38
|
constructor(name_: string | undefined, onInvalidate_: () => void, errorHandler_?: ((error: any, derivation: IDerivation) => void) | undefined, requiresObservable_?: any);
|
|
46
39
|
get isDisposed(): boolean;
|
|
47
40
|
set isDisposed(newValue: boolean);
|
|
@@ -64,7 +57,6 @@ export declare class Reaction implements IDerivation, IReactionPublic {
|
|
|
64
57
|
dispose(): void;
|
|
65
58
|
getDisposer_(abortSignal?: GenericAbortSignal): IReactionDisposer;
|
|
66
59
|
toString(): string;
|
|
67
|
-
trace(enterBreakPoint?: boolean): void;
|
|
68
60
|
}
|
|
69
61
|
export declare function onReactionError(handler: (error: any, derivation: IDerivation) => void): Lambda;
|
|
70
62
|
export declare function runReactions(): void;
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const niceErrors: {
|
|
1
|
+
export declare const niceErrors: {
|
|
2
2
|
readonly 0: "Invalid value for configuration 'enforceActions', expected 'never', 'always' or 'observed'";
|
|
3
3
|
readonly 1: (annotationType: any, key: PropertyKey) => string;
|
|
4
4
|
readonly 5: "'keys()' can only be used on observable objects, arrays, sets and maps";
|
|
@@ -13,12 +13,9 @@ declare const niceErrors: {
|
|
|
13
13
|
readonly 14: "Intercept handlers should return nothing or a change object";
|
|
14
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
|
-
readonly 17: (index: any, length: any) => string;
|
|
17
|
-
readonly 18: "mobx.map requires Map polyfill for the current browser. Check babel-polyfill or core-js/es6/map.js";
|
|
18
16
|
readonly 19: (other: any) => string;
|
|
19
17
|
readonly 20: (other: any) => string;
|
|
20
18
|
readonly 21: (dataStructure: any) => string;
|
|
21
|
-
readonly 22: "mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js";
|
|
22
19
|
readonly 23: "It is not possible to get index atoms from arrays";
|
|
23
20
|
readonly 24: (thing: any) => string;
|
|
24
21
|
readonly 25: (property: any, name: any) => string;
|
|
@@ -36,6 +33,11 @@ declare const niceErrors: {
|
|
|
36
33
|
readonly 37: (method: any) => string;
|
|
37
34
|
readonly 38: "'ownKeys()' can only be used on observable objects";
|
|
38
35
|
readonly 39: "'defineProperty()' can only be used on observable objects";
|
|
36
|
+
readonly 40: (length: any) => string;
|
|
37
|
+
readonly 41: (other: any) => string;
|
|
38
|
+
readonly 42: (key: any) => string;
|
|
39
|
+
readonly 43: (annotationType: any, name: any, kind: any) => string;
|
|
40
|
+
readonly 44: (annotationType: any) => string;
|
|
39
41
|
};
|
|
40
42
|
declare const errors: typeof niceErrors;
|
|
41
43
|
export declare function die(error: string | keyof typeof errors, ...args: any[]): never;
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./errors";
|
|
1
|
+
export { die } from "./errors";
|
|
3
2
|
export * from "./utils/utils";
|
|
4
3
|
export * from "./api/decorators";
|
|
5
4
|
export * from "./core/atom";
|
|
@@ -36,7 +35,6 @@ export * from "./api/isobservable";
|
|
|
36
35
|
export * from "./api/object-api";
|
|
37
36
|
export * from "./api/observe";
|
|
38
37
|
export * from "./api/tojs";
|
|
39
|
-
export * from "./api/trace";
|
|
40
38
|
export * from "./api/transaction";
|
|
41
39
|
export * from "./api/when";
|
|
42
40
|
export * from "./types/dynamicobject";
|
|
@@ -47,7 +45,6 @@ export * from "./types/observablearray";
|
|
|
47
45
|
export * from "./types/observablemap";
|
|
48
46
|
export * from "./types/observableset";
|
|
49
47
|
export * from "./types/observableobject";
|
|
50
|
-
export * from "./types/legacyobservablearray";
|
|
51
48
|
export * from "./types/type-utils";
|
|
52
49
|
export * from "./utils/eq";
|
|
53
50
|
export * from "./utils/iterable";
|