mobx 6.2.0 → 6.3.3
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 +44 -5
- package/README.md +4 -4
- package/dist/api/autorun.d.ts +3 -3
- package/dist/api/flow.d.ts +1 -0
- package/dist/api/object-api.d.ts +2 -0
- package/dist/errors.d.ts +2 -0
- package/dist/mobx.cjs.development.js +94 -33
- 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 +1 -1
- package/dist/mobx.esm.development.js +93 -34
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +93 -34
- 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.umd.development.js +94 -33
- 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/package.json +1 -1
- package/src/api/autorun.ts +5 -5
- package/src/api/flow.ts +6 -1
- package/src/api/object-api.ts +14 -0
- package/src/api/observable.ts +4 -4
- package/src/api/tojs.ts +5 -4
- package/src/api/when.ts +1 -1
- package/src/core/computedvalue.ts +8 -6
- package/src/core/derivation.ts +4 -2
- package/src/errors.ts +14 -1
- package/src/mobx.ts +3 -1
- package/src/types/autoannotation.ts +2 -1
- package/src/types/dynamicobject.ts +1 -1
- package/src/types/flowannotation.ts +12 -3
- package/src/utils/comparer.ts +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# mobx
|
|
2
2
|
|
|
3
|
+
## 6.3.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`d78a1592`](https://github.com/mobxjs/mobx/commit/d78a15929052b96698b3355a0b4c8335750422db) [#2902](https://github.com/mobxjs/mobx/pull/2902) Thanks [@z3rog](https://github.com/z3rog)! - chore: observable use internal constants
|
|
8
|
+
|
|
9
|
+
* [`db21d85f`](https://github.com/mobxjs/mobx/commit/db21d85fcd41c6c142998f53e722ee0a0e9b5c18) [#2998](https://github.com/mobxjs/mobx/pull/2998) Thanks [@urugator](https://github.com/urugator)! - `trace()`: log when computed becomes suspended
|
|
10
|
+
`requiresReaction` warns instead of throwing
|
|
11
|
+
|
|
12
|
+
- [`b9fa119c`](https://github.com/mobxjs/mobx/commit/b9fa119c90e23d4b327763189f24c00be2fb2c26) [#3056](https://github.com/mobxjs/mobx/pull/3056) Thanks [@upsuper](https://github.com/upsuper)! - Create WHEN_TIMEOUT error earlier to capture useful stack
|
|
13
|
+
|
|
14
|
+
* [`99491ec2`](https://github.com/mobxjs/mobx/commit/99491ec2d315a3a01cdbe40d9a24d920a09cbd0e) [#2972](https://github.com/mobxjs/mobx/pull/2972) Thanks [@kk-gjyang](https://github.com/kk-gjyang)! - Polyfill `Object.is` for old/unsupported browsers
|
|
15
|
+
|
|
16
|
+
- [`0d28db8a`](https://github.com/mobxjs/mobx/commit/0d28db8a0ba99f5cce744bb83b5bd88ec45a7e41) [#2927](https://github.com/mobxjs/mobx/pull/2927) Thanks [@upsuper](https://github.com/upsuper)! - Give proper typing to opts.equals of reaction
|
|
17
|
+
|
|
18
|
+
* [`c6dc925c`](https://github.com/mobxjs/mobx/commit/c6dc925c6cf7eeff9237ee07c55927a7bbc14cb7) [#2985](https://github.com/mobxjs/mobx/pull/2985) Thanks [@fecqs](https://github.com/fecqs)! - Remove duplicate global property check
|
|
19
|
+
|
|
20
|
+
## 6.3.2
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- [`4011b378`](https://github.com/mobxjs/mobx/commit/4011b3789d57e3dab0b85a835fe2979033133ce9) [#2949](https://github.com/mobxjs/mobx/pull/2949) Thanks [@urugator](https://github.com/urugator)! - fix #2948: flow ignores `autoBind` option
|
|
25
|
+
|
|
26
|
+
## 6.3.1
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- [`d678ebd7`](https://github.com/mobxjs/mobx/commit/d678ebd7e54efb3aeae4541f87f5bcf93a623ec6) [#2944](https://github.com/mobxjs/mobx/pull/2944) Thanks [@urugator](https://github.com/urugator)! - Fix [#2941](https://github.com/mobxjs/mobx/issues/2941) - flow.bound replaces method on proto with bound function
|
|
31
|
+
|
|
32
|
+
## 6.3.0
|
|
33
|
+
|
|
34
|
+
### Minor Changes
|
|
35
|
+
|
|
36
|
+
- [`035bf409`](https://github.com/mobxjs/mobx/commit/035bf4096dd72d296af1fc25304adaade73cc7eb) [#2906](https://github.com/mobxjs/mobx/pull/2906) Thanks [@urugator](https://github.com/urugator)! - Provide `flow.bound` annotation/decorator
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- [`3dedb4d4`](https://github.com/mobxjs/mobx/commit/3dedb4d4b5376f3991183923838da942a9a81506) [#2904](https://github.com/mobxjs/mobx/pull/2904) Thanks [@ahoisl](https://github.com/ahoisl)! - Make toJS work with computed value props
|
|
41
|
+
|
|
3
42
|
## 6.2.0
|
|
4
43
|
|
|
5
44
|
### Minor Changes
|
|
@@ -175,12 +214,12 @@ Support the ongoing maintenance at: https://opencollective.com/mobx
|
|
|
175
214
|
|
|
176
215
|
### New features
|
|
177
216
|
|
|
178
|
-
- [`makeObservable(target, annotations)`](
|
|
179
|
-
- [`makeAutoObservable(target)`](
|
|
180
|
-
- MobX 6 can be used in both modern environments, and environments that don't support Proxy. So both MobX 4 and 5 users can upgrade to 6. See [proxy support](
|
|
217
|
+
- [`makeObservable(target, annotations)`](../../docs/observable-state.md#makeobservable) is now the recommended way to make objects with a fixed shape observable, such as classes.
|
|
218
|
+
- [`makeAutoObservable(target)`](../../docs/observable-state.md#makeautoobservable) will automatically determine the annotations used by `makeObservable`. Methods will be marked as 'autoAction', so that they can be used both from a computed value or as standalone method.
|
|
219
|
+
- MobX 6 can be used in both modern environments, and environments that don't support Proxy. So both MobX 4 and 5 users can upgrade to 6. See [proxy support](../../docs/configuration.md#proxy-support) for more details.
|
|
181
220
|
- `observable.array` now supports `{ proxy: false }` as option.
|
|
182
221
|
- `reaction`'s effect function now receives the previous value seen by the reaction as second argument.
|
|
183
|
-
- `flow` can now be used as annotation as well. You might need `flowResult` in case you use TypeScript to extract the correct result type. [details](
|
|
222
|
+
- `flow` can now be used as annotation as well. You might need `flowResult` in case you use TypeScript to extract the correct result type. [details](../../docs/actions.md#using-flow-instead-of-async--await-).
|
|
184
223
|
|
|
185
224
|
### Breaking changes
|
|
186
225
|
|
|
@@ -188,7 +227,7 @@ Support the ongoing maintenance at: https://opencollective.com/mobx
|
|
|
188
227
|
|
|
189
228
|
- The `decorate` API has been removed, and needs to be replaced by `makeObservable` in the constructor of the targeted class. It accepts the same arguments. The `mobx-undecorate` can transform this automatically.
|
|
190
229
|
- When using `extendObservable` / `observable`, fields that contained functions used to be turned into observables. This is no longer the case, they will be converted into `autoActions`.
|
|
191
|
-
- [Strict mode](
|
|
230
|
+
- [Strict mode](../../docs/configuration.md#enforceactions) for actions is now enabled by default in `observed` mode.
|
|
192
231
|
- `toJS` no longer takes any options. It no longer converts Maps and Sets to plain data structures. Generic, flexible serialization of data structures is out of scope for the MobX project, and writing custom serialization methods is a much more scalable approach to serialization (tip: leverage `computed`s to define how class instances should be serialized).
|
|
193
232
|
- The methods `intercept` and `observe` are no longer exposed on observable arrays, maps and boxed observables. Import them as utility from mobx instead: `import { observe, intercept } from "mobx"`, and pass the collection as first argument: `observer(collection, callback)`. Note that we still recommend to avoid these APIs.
|
|
194
233
|
- `observableMap.toPOJO()`, `observableMap.toJS()` have been dropped. Use `new Map(observableMap)` instead if you want to convert an observable map to a plain Map shallowly.
|
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ _Simple, scalable state management._
|
|
|
17
17
|
|
|
18
18
|
MobX is made possible by the generosity of the sponsors below, and many other [individual backers](docs/backers-sponsors.md#backers). Sponsoring directly impacts the longevity of this project.
|
|
19
19
|
|
|
20
|
-
**🥇Gold sponsors (\$3000+ total contribution):** <br/>
|
|
20
|
+
**🥇 Gold sponsors (\$3000+ total contribution):** <br/>
|
|
21
21
|
<a href="https://mendix.com/"><img src="https://mobx.js.org/assets/mendix-logo.png" align="center" width="100" title="Mendix" alt="Mendix" /></a>
|
|
22
22
|
<a href="https://frontendmasters.com/"><img src="https://mobx.js.org/assets/frontendmasters.jpg" align="center" width="100" title="Frontend Masters" alt="Frontend Masters"></a>
|
|
23
23
|
<a href="https://opensource.facebook.com/"><img src="https://mobx.js.org/assets/fbos.jpeg" align="center" width="100" title="Facebook Open Source" alt="Facebook Open Source" /></a>
|
|
@@ -26,15 +26,15 @@ MobX is made possible by the generosity of the sponsors below, and many other [i
|
|
|
26
26
|
<a href="https://coinbase.com/"><img src="https://mobx.js.org/assets/coinbase.jpeg" align="center" width="100" title="Coinbase" alt="Coinbase" /></a>
|
|
27
27
|
<a href="https://www.canva.com/"><img src="https://mobx.js.org/assets/canva.png" align="center" width="100" title="Canva" alt="Canva" /></a>
|
|
28
28
|
|
|
29
|
-
**🥈Silver sponsors (\$100+
|
|
29
|
+
**🥈 Silver sponsors (\$100+ per month):**<br/>
|
|
30
30
|
<a href="https://www.codefirst.co.uk/"><img src="https://mobx.js.org/assets/codefirst.png" align="center" width="100" title="CodeFirst" alt="CodeFirst"/></a>
|
|
31
|
-
<a href="https://www.
|
|
31
|
+
<a href="https://www.dcsl.com/"><img src="https://mobx.js.org/assets/dcsl.png" align="center" width="100" title="DCSL Guidesmiths" alt="DCSL Guidesmiths"/></a>
|
|
32
32
|
<a href="https://www.bugsnag.com/platforms/react-error-reporting?utm_source=MobX&utm_medium=Website&utm_content=open-source&utm_campaign=2019-community&utm_term=20190913"><img src="https://mobx.js.org/assets/bugsnag.jpg" align="center" width="100" title="Bugsnag" alt="Bugsnag"/></a>
|
|
33
33
|
<a href="https://curology.com/blog/tech"><img src="https://mobx.js.org/assets/curology.png" align="center" width="100" title="Curology" alt="Curology"/></a>
|
|
34
34
|
<a href="https://modulz.app/"><img src="https://mobx.js.org/assets/modulz.png" align="center" width="100" title="Modulz" alt="Modulz"/></a>
|
|
35
35
|
<a href="https://space307.com/?utm_source=sponsorship&utm_medium=mobx&utm_campaign=readme"><img src="https://mobx.js.org/assets/space307.png" align="center" width="100" title="Space307" alt="Space307"/></a>
|
|
36
36
|
|
|
37
|
-
**🥉Bronze sponsors (\$500+ total contributions):**<br/>
|
|
37
|
+
**🥉 Bronze sponsors (\$500+ total contributions):**<br/>
|
|
38
38
|
<a href="https://mantro.net/jobs/warlock"><img src="https://mobx.js.org/assets/mantro.png" align="center" width="100" title="mantro GmbH" alt="mantro GmbH"></a>
|
|
39
39
|
<a href="https://www.algolia.com/"><img src="https://mobx.js.org/assets/algolia.jpg" align="center" width="100" title="Algolia" alt="Algolia" /></a>
|
|
40
40
|
<a href="https://talentplot.com/"><img src="https://mobx.js.org/assets/talentplot.png" align="center" width="100" title="talentplot" alt="talentplot"></a>
|
package/dist/api/autorun.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ export interface IAutorunOptions {
|
|
|
17
17
|
* @returns disposer function, which can be used to stop the view from being updated in the future.
|
|
18
18
|
*/
|
|
19
19
|
export declare function autorun(view: (r: IReactionPublic) => any, opts?: IAutorunOptions): IReactionDisposer;
|
|
20
|
-
export declare type IReactionOptions = IAutorunOptions & {
|
|
20
|
+
export declare type IReactionOptions<T> = IAutorunOptions & {
|
|
21
21
|
fireImmediately?: boolean;
|
|
22
|
-
equals?: IEqualsComparer<
|
|
22
|
+
equals?: IEqualsComparer<T>;
|
|
23
23
|
};
|
|
24
|
-
export declare function reaction<T>(expression: (r: IReactionPublic) => T, effect: (arg: T, prev: T, r: IReactionPublic) => void, opts?: IReactionOptions): IReactionDisposer;
|
|
24
|
+
export declare function reaction<T>(expression: (r: IReactionPublic) => T, effect: (arg: T, prev: T, r: IReactionPublic) => void, opts?: IReactionOptions<T>): IReactionDisposer;
|
package/dist/api/flow.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare type CancellablePromise<T> = Promise<T> & {
|
|
|
10
10
|
};
|
|
11
11
|
interface Flow extends Annotation, PropertyDecorator {
|
|
12
12
|
<R, Args extends any[]>(generator: (...args: Args) => Generator<any, R, any> | AsyncGenerator<any, R, any>): (...args: Args) => CancellablePromise<R>;
|
|
13
|
+
bound: Annotation & PropertyDecorator;
|
|
13
14
|
}
|
|
14
15
|
export declare const flow: Flow;
|
|
15
16
|
export declare function flowResult<T>(result: T): T extends Generator<any, infer R, any> ? CancellablePromise<R> : T extends CancellablePromise<any> ? T : never;
|
package/dist/api/object-api.d.ts
CHANGED
|
@@ -32,3 +32,5 @@ export declare function has<T extends Object>(obj: T, key: string): boolean;
|
|
|
32
32
|
export declare function get<K, V>(obj: ObservableMap<K, V>, key: K): V | undefined;
|
|
33
33
|
export declare function get<T>(obj: IObservableArray<T>, index: number): T | undefined;
|
|
34
34
|
export declare function get<T extends Object>(obj: T, key: string): any;
|
|
35
|
+
export declare function apiDefineProperty(obj: Object, key: PropertyKey, descriptor: PropertyDescriptor): any;
|
|
36
|
+
export declare function apiOwnKeys(obj: Object): any;
|
package/dist/errors.d.ts
CHANGED
|
@@ -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;
|
|
@@ -7,6 +7,18 @@ var niceErrors = {
|
|
|
7
7
|
1: function _(annotationType, key) {
|
|
8
8
|
return "Cannot apply '" + annotationType + "' to '" + key.toString() + "': Field not found.";
|
|
9
9
|
},
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
2(prop) {
|
|
13
|
+
return `invalid decorator for '${prop.toString()}'`
|
|
14
|
+
},
|
|
15
|
+
3(prop) {
|
|
16
|
+
return `Cannot decorate '${prop.toString()}': action can only be used on properties with a function value.`
|
|
17
|
+
},
|
|
18
|
+
4(prop) {
|
|
19
|
+
return `Cannot decorate '${prop.toString()}': computed can only be used on getter properties.`
|
|
20
|
+
},
|
|
21
|
+
*/
|
|
10
22
|
5: "'keys()' can only be used on observable objects, arrays, sets and maps",
|
|
11
23
|
6: "'values()' can only be used on observable objects, arrays, sets and maps",
|
|
12
24
|
7: "'entries()' can only be used on observable objects, arrays and maps",
|
|
@@ -63,7 +75,9 @@ var niceErrors = {
|
|
|
63
75
|
36: "isolateGlobalState should be called before MobX is running any reactions",
|
|
64
76
|
37: function _(method) {
|
|
65
77
|
return "[mobx] `observableArray." + method + "()` mutates the array in-place, which is not allowed inside a derivation. Use `array.slice()." + method + "()` instead";
|
|
66
|
-
}
|
|
78
|
+
},
|
|
79
|
+
38: "'ownKeys()' can only be used on observable objects",
|
|
80
|
+
39: "'defineProperty()' can only be used on observable objects"
|
|
67
81
|
};
|
|
68
82
|
var errors = niceErrors ;
|
|
69
83
|
function die(error) {
|
|
@@ -500,7 +514,8 @@ function shallowComparer(a, b) {
|
|
|
500
514
|
}
|
|
501
515
|
|
|
502
516
|
function defaultComparer(a, b) {
|
|
503
|
-
return Object.is(a, b);
|
|
517
|
+
if (Object.is) return Object.is(a, b);
|
|
518
|
+
return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
|
|
504
519
|
}
|
|
505
520
|
|
|
506
521
|
var comparer = {
|
|
@@ -698,6 +713,8 @@ function createFlowAnnotation(name, options) {
|
|
|
698
713
|
}
|
|
699
714
|
|
|
700
715
|
function make_$2(adm, key, descriptor, source) {
|
|
716
|
+
var _this$options_;
|
|
717
|
+
|
|
701
718
|
// own
|
|
702
719
|
if (source === adm.target_) {
|
|
703
720
|
return this.extend_(adm, key, descriptor, false) === null ? 0
|
|
@@ -706,8 +723,15 @@ function make_$2(adm, key, descriptor, source) {
|
|
|
706
723
|
/* Continue */
|
|
707
724
|
;
|
|
708
725
|
} // prototype
|
|
726
|
+
// bound - must annotate protos to support super.flow()
|
|
709
727
|
|
|
710
728
|
|
|
729
|
+
if (((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) && !isFlow(adm.target_[key])) {
|
|
730
|
+
if (this.extend_(adm, key, descriptor, false) === null) return 0
|
|
731
|
+
/* Cancel */
|
|
732
|
+
;
|
|
733
|
+
}
|
|
734
|
+
|
|
711
735
|
if (isFlow(descriptor.value)) {
|
|
712
736
|
// A prototype could have been annotated already by other constructor,
|
|
713
737
|
// rest of the proto chain must be annotated already
|
|
@@ -716,7 +740,7 @@ function make_$2(adm, key, descriptor, source) {
|
|
|
716
740
|
;
|
|
717
741
|
}
|
|
718
742
|
|
|
719
|
-
var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, false);
|
|
743
|
+
var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, false, false);
|
|
720
744
|
defineProperty(source, key, flowDescriptor);
|
|
721
745
|
return 2
|
|
722
746
|
/* Continue */
|
|
@@ -724,7 +748,9 @@ function make_$2(adm, key, descriptor, source) {
|
|
|
724
748
|
}
|
|
725
749
|
|
|
726
750
|
function extend_$2(adm, key, descriptor, proxyTrap) {
|
|
727
|
-
var
|
|
751
|
+
var _this$options_2;
|
|
752
|
+
|
|
753
|
+
var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, (_this$options_2 = this.options_) == null ? void 0 : _this$options_2.bound);
|
|
728
754
|
return adm.defineProperty_(key, flowDescriptor, proxyTrap);
|
|
729
755
|
}
|
|
730
756
|
|
|
@@ -737,15 +763,23 @@ function assertFlowDescriptor(adm, _ref, key, _ref2) {
|
|
|
737
763
|
}
|
|
738
764
|
}
|
|
739
765
|
|
|
740
|
-
function createFlowDescriptor(adm, annotation, key, descriptor, // provides ability to disable safeDescriptors for prototypes
|
|
766
|
+
function createFlowDescriptor(adm, annotation, key, descriptor, bound, // provides ability to disable safeDescriptors for prototypes
|
|
741
767
|
safeDescriptors) {
|
|
742
768
|
if (safeDescriptors === void 0) {
|
|
743
769
|
safeDescriptors = globalState.safeDescriptors;
|
|
744
770
|
}
|
|
745
771
|
|
|
746
772
|
assertFlowDescriptor(adm, annotation, key, descriptor);
|
|
773
|
+
var value = descriptor.value;
|
|
774
|
+
|
|
775
|
+
if (bound) {
|
|
776
|
+
var _adm$proxy_;
|
|
777
|
+
|
|
778
|
+
value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
|
|
779
|
+
}
|
|
780
|
+
|
|
747
781
|
return {
|
|
748
|
-
value: flow(
|
|
782
|
+
value: flow(value),
|
|
749
783
|
// Non-configurable for classes
|
|
750
784
|
// prevents accidental field redefinition in subclass
|
|
751
785
|
configurable: safeDescriptors ? adm.isPlainObject_ : true,
|
|
@@ -835,7 +869,7 @@ function createAutoAnnotation(options) {
|
|
|
835
869
|
}
|
|
836
870
|
|
|
837
871
|
function make_$5(adm, key, descriptor, source) {
|
|
838
|
-
var _this$
|
|
872
|
+
var _this$options_3, _this$options_4;
|
|
839
873
|
|
|
840
874
|
// getter -> computed
|
|
841
875
|
if (descriptor.get) {
|
|
@@ -870,22 +904,25 @@ function make_$5(adm, key, descriptor, source) {
|
|
|
870
904
|
|
|
871
905
|
|
|
872
906
|
if (source !== adm.target_ && typeof descriptor.value === "function") {
|
|
873
|
-
var _this$
|
|
907
|
+
var _this$options_2;
|
|
874
908
|
|
|
875
909
|
if (isGenerator(descriptor.value)) {
|
|
876
|
-
|
|
910
|
+
var _this$options_;
|
|
911
|
+
|
|
912
|
+
var flowAnnotation = ((_this$options_ = this.options_) == null ? void 0 : _this$options_.autoBind) ? flow.bound : flow;
|
|
913
|
+
return flowAnnotation.make_(adm, key, descriptor, source);
|
|
877
914
|
}
|
|
878
915
|
|
|
879
|
-
var actionAnnotation = ((_this$
|
|
916
|
+
var actionAnnotation = ((_this$options_2 = this.options_) == null ? void 0 : _this$options_2.autoBind) ? autoAction.bound : autoAction;
|
|
880
917
|
return actionAnnotation.make_(adm, key, descriptor, source);
|
|
881
918
|
} // other -> observable
|
|
882
919
|
// Copy props from proto as well, see test:
|
|
883
920
|
// "decorate should work with Object.create"
|
|
884
921
|
|
|
885
922
|
|
|
886
|
-
var observableAnnotation = ((_this$
|
|
923
|
+
var observableAnnotation = ((_this$options_3 = this.options_) == null ? void 0 : _this$options_3.deep) === false ? observable.ref : observable; // if function respect autoBind option
|
|
887
924
|
|
|
888
|
-
if (typeof descriptor.value === "function" && ((_this$
|
|
925
|
+
if (typeof descriptor.value === "function" && ((_this$options_4 = this.options_) == null ? void 0 : _this$options_4.autoBind)) {
|
|
889
926
|
var _adm$proxy_;
|
|
890
927
|
|
|
891
928
|
descriptor.value = descriptor.value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
|
|
@@ -895,7 +932,7 @@ function make_$5(adm, key, descriptor, source) {
|
|
|
895
932
|
}
|
|
896
933
|
|
|
897
934
|
function extend_$5(adm, key, descriptor, proxyTrap) {
|
|
898
|
-
var _this$
|
|
935
|
+
var _this$options_5, _this$options_6;
|
|
899
936
|
|
|
900
937
|
// getter -> computed
|
|
901
938
|
if (descriptor.get) {
|
|
@@ -913,16 +950,20 @@ function extend_$5(adm, key, descriptor, proxyTrap) {
|
|
|
913
950
|
// if function respect autoBind option
|
|
914
951
|
|
|
915
952
|
|
|
916
|
-
if (typeof descriptor.value === "function" && ((_this$
|
|
953
|
+
if (typeof descriptor.value === "function" && ((_this$options_5 = this.options_) == null ? void 0 : _this$options_5.autoBind)) {
|
|
917
954
|
var _adm$proxy_2;
|
|
918
955
|
|
|
919
956
|
descriptor.value = descriptor.value.bind((_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_);
|
|
920
957
|
}
|
|
921
958
|
|
|
922
|
-
var observableAnnotation = ((_this$
|
|
959
|
+
var observableAnnotation = ((_this$options_6 = this.options_) == null ? void 0 : _this$options_6.deep) === false ? observable.ref : observable;
|
|
923
960
|
return observableAnnotation.extend_(adm, key, descriptor, proxyTrap);
|
|
924
961
|
}
|
|
925
962
|
|
|
963
|
+
var OBSERVABLE = "observable";
|
|
964
|
+
var OBSERVABLE_REF = "observable.ref";
|
|
965
|
+
var OBSERVABLE_SHALLOW = "observable.shallow";
|
|
966
|
+
var OBSERVABLE_STRUCT = "observable.struct"; // Predefined bags of create observable options, to avoid allocating temporarily option objects
|
|
926
967
|
// in the majority of cases
|
|
927
968
|
|
|
928
969
|
var defaultCreateObservableOptions = {
|
|
@@ -935,14 +976,14 @@ Object.freeze(defaultCreateObservableOptions);
|
|
|
935
976
|
function asCreateObservableOptions(thing) {
|
|
936
977
|
return thing || defaultCreateObservableOptions;
|
|
937
978
|
}
|
|
938
|
-
var observableAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
939
|
-
var observableRefAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
979
|
+
var observableAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE);
|
|
980
|
+
var observableRefAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE_REF, {
|
|
940
981
|
enhancer: referenceEnhancer
|
|
941
982
|
});
|
|
942
|
-
var observableShallowAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
983
|
+
var observableShallowAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE_SHALLOW, {
|
|
943
984
|
enhancer: shallowEnhancer
|
|
944
985
|
});
|
|
945
|
-
var observableStructAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
986
|
+
var observableStructAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE_STRUCT, {
|
|
946
987
|
enhancer: refStructEnhancer
|
|
947
988
|
});
|
|
948
989
|
var observableDecoratorAnnotation = /*#__PURE__*/createDecoratorAnnotation(observableAnnotation);
|
|
@@ -1547,6 +1588,10 @@ var ComputedValue = /*#__PURE__*/function () {
|
|
|
1547
1588
|
if (!this.keepAlive_) {
|
|
1548
1589
|
clearObserving(this);
|
|
1549
1590
|
this.value_ = undefined; // don't hold on to computed value!
|
|
1591
|
+
|
|
1592
|
+
if ( this.isTracing_ !== TraceMode.NONE) {
|
|
1593
|
+
console.log("[mobx.trace] Computed value '" + this.name_ + "' was suspended and it will recompute on the next access.");
|
|
1594
|
+
}
|
|
1550
1595
|
}
|
|
1551
1596
|
};
|
|
1552
1597
|
|
|
@@ -1579,16 +1624,12 @@ var ComputedValue = /*#__PURE__*/function () {
|
|
|
1579
1624
|
|
|
1580
1625
|
_proto.warnAboutUntrackedRead_ = function warnAboutUntrackedRead_() {
|
|
1581
1626
|
|
|
1582
|
-
if (this.requiresReaction_ === true) {
|
|
1583
|
-
die("[mobx] Computed value " + this.name_ + " is read outside a reactive context");
|
|
1584
|
-
}
|
|
1585
|
-
|
|
1586
1627
|
if (this.isTracing_ !== TraceMode.NONE) {
|
|
1587
|
-
console.log("[mobx.trace] '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute");
|
|
1628
|
+
console.log("[mobx.trace] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
|
|
1588
1629
|
}
|
|
1589
1630
|
|
|
1590
|
-
if (globalState.computedRequiresReaction) {
|
|
1591
|
-
console.warn("[mobx] Computed value " + this.name_ + " is being read outside a reactive context. Doing a full recompute");
|
|
1631
|
+
if (globalState.computedRequiresReaction || this.requiresReaction_) {
|
|
1632
|
+
console.warn("[mobx] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
|
|
1592
1633
|
}
|
|
1593
1634
|
};
|
|
1594
1635
|
|
|
@@ -1721,7 +1762,7 @@ function checkIfStateModificationsAreAllowed(atom) {
|
|
|
1721
1762
|
}
|
|
1722
1763
|
function checkIfStateReadsAreAllowed(observable) {
|
|
1723
1764
|
if ( !globalState.allowStateReads && globalState.observableRequiresReaction) {
|
|
1724
|
-
console.warn("[mobx] Observable " + observable.name_ + " being read outside a reactive context");
|
|
1765
|
+
console.warn("[mobx] Observable '" + observable.name_ + "' being read outside a reactive context.");
|
|
1725
1766
|
}
|
|
1726
1767
|
}
|
|
1727
1768
|
/**
|
|
@@ -1765,7 +1806,7 @@ function warnAboutDerivationWithoutDependencies(derivation) {
|
|
|
1765
1806
|
if (derivation.observing_.length !== 0) return;
|
|
1766
1807
|
|
|
1767
1808
|
if (globalState.reactionRequiresObservable || derivation.requiresObservable_) {
|
|
1768
|
-
console.warn("[mobx] Derivation " + derivation.name_ + " is created/updated without reading any observable value");
|
|
1809
|
+
console.warn("[mobx] Derivation '" + derivation.name_ + "' is created/updated without reading any observable value.");
|
|
1769
1810
|
}
|
|
1770
1811
|
}
|
|
1771
1812
|
/**
|
|
@@ -2785,6 +2826,9 @@ function isFlowCancellationError(error) {
|
|
|
2785
2826
|
return error instanceof FlowCancellationError;
|
|
2786
2827
|
}
|
|
2787
2828
|
var flowAnnotation = /*#__PURE__*/createFlowAnnotation("flow");
|
|
2829
|
+
var flowBoundAnnotation = /*#__PURE__*/createFlowAnnotation("flow.bound", {
|
|
2830
|
+
bound: true
|
|
2831
|
+
});
|
|
2788
2832
|
var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
2789
2833
|
// @flow
|
|
2790
2834
|
if (isStringish(arg2)) {
|
|
@@ -2870,6 +2914,7 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2870
2914
|
res.isMobXFlow = true;
|
|
2871
2915
|
return res;
|
|
2872
2916
|
}, flowAnnotation);
|
|
2917
|
+
flow.bound = /*#__PURE__*/createDecoratorAnnotation(flowBoundAnnotation);
|
|
2873
2918
|
|
|
2874
2919
|
function cancelPromise(promise) {
|
|
2875
2920
|
if (isFunction(promise.cancel)) promise.cancel();
|
|
@@ -3094,6 +3139,20 @@ function get(obj, key) {
|
|
|
3094
3139
|
|
|
3095
3140
|
die(11);
|
|
3096
3141
|
}
|
|
3142
|
+
function apiDefineProperty(obj, key, descriptor) {
|
|
3143
|
+
if (isObservableObject(obj)) {
|
|
3144
|
+
return obj[$mobx].defineProperty_(key, descriptor);
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3147
|
+
die(39);
|
|
3148
|
+
}
|
|
3149
|
+
function apiOwnKeys(obj) {
|
|
3150
|
+
if (isObservableObject(obj)) {
|
|
3151
|
+
return obj[$mobx].ownKeys_();
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
die(38);
|
|
3155
|
+
}
|
|
3097
3156
|
|
|
3098
3157
|
function observe(thing, propOrCb, cbOrFire, fireImmediately) {
|
|
3099
3158
|
if (isFunction(cbOrFire)) return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);else return observeObservable(thing, propOrCb, cbOrFire);
|
|
@@ -3114,7 +3173,7 @@ function cache(map, key, value) {
|
|
|
3114
3173
|
|
|
3115
3174
|
function toJSHelper(source, __alreadySeen) {
|
|
3116
3175
|
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source)) return source;
|
|
3117
|
-
if (isObservableValue(source)) return toJSHelper(source.get(), __alreadySeen);
|
|
3176
|
+
if (isObservableValue(source) || isComputedValue(source)) return toJSHelper(source.get(), __alreadySeen);
|
|
3118
3177
|
|
|
3119
3178
|
if (__alreadySeen.has(source)) {
|
|
3120
3179
|
return __alreadySeen.get(source);
|
|
@@ -3148,7 +3207,7 @@ function toJSHelper(source, __alreadySeen) {
|
|
|
3148
3207
|
// must be observable object
|
|
3149
3208
|
var _res3 = cache(__alreadySeen, source, {});
|
|
3150
3209
|
|
|
3151
|
-
source
|
|
3210
|
+
apiOwnKeys(source).forEach(function (key) {
|
|
3152
3211
|
if (objectPrototype.propertyIsEnumerable.call(source, key)) {
|
|
3153
3212
|
_res3[key] = toJSHelper(source[key], __alreadySeen);
|
|
3154
3213
|
}
|
|
@@ -3231,10 +3290,10 @@ function _when(predicate, effect, opts) {
|
|
|
3231
3290
|
var timeoutHandle;
|
|
3232
3291
|
|
|
3233
3292
|
if (typeof opts.timeout === "number") {
|
|
3293
|
+
var error = new Error("WHEN_TIMEOUT");
|
|
3234
3294
|
timeoutHandle = setTimeout(function () {
|
|
3235
3295
|
if (!disposer[$mobx].isDisposed_) {
|
|
3236
3296
|
disposer();
|
|
3237
|
-
var error = new Error("WHEN_TIMEOUT");
|
|
3238
3297
|
if (opts.onError) opts.onError(error);else throw error;
|
|
3239
3298
|
}
|
|
3240
3299
|
}, opts.timeout);
|
|
@@ -3321,7 +3380,7 @@ var objectProxyTraps = {
|
|
|
3321
3380
|
return (_getAdm$definePropert = getAdm(target).defineProperty_(name, descriptor)) != null ? _getAdm$definePropert : true;
|
|
3322
3381
|
},
|
|
3323
3382
|
ownKeys: function ownKeys(target) {
|
|
3324
|
-
if ( globalState.trackingDerivation) warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use
|
|
3383
|
+
if ( globalState.trackingDerivation) warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use 'keys' from 'mobx' instead.");
|
|
3325
3384
|
return getAdm(target).ownKeys_();
|
|
3326
3385
|
},
|
|
3327
3386
|
preventExtensions: function preventExtensions(target) {
|
|
@@ -5684,7 +5743,7 @@ function isAnnotation(thing) {
|
|
|
5684
5743
|
* - utils/ Utility stuff.
|
|
5685
5744
|
*
|
|
5686
5745
|
*/
|
|
5687
|
-
["Symbol", "Map", "Set"
|
|
5746
|
+
["Symbol", "Map", "Set"].forEach(function (m) {
|
|
5688
5747
|
var g = getGlobal();
|
|
5689
5748
|
|
|
5690
5749
|
if (typeof g[m] === "undefined") {
|
|
@@ -5726,6 +5785,7 @@ exports.comparer = comparer;
|
|
|
5726
5785
|
exports.computed = computed;
|
|
5727
5786
|
exports.configure = configure;
|
|
5728
5787
|
exports.createAtom = createAtom;
|
|
5788
|
+
exports.defineProperty = apiDefineProperty;
|
|
5729
5789
|
exports.entries = entries;
|
|
5730
5790
|
exports.extendObservable = extendObservable;
|
|
5731
5791
|
exports.flow = flow;
|
|
@@ -5758,6 +5818,7 @@ exports.onBecomeObserved = onBecomeObserved;
|
|
|
5758
5818
|
exports.onBecomeUnobserved = onBecomeUnobserved;
|
|
5759
5819
|
exports.onReactionError = onReactionError;
|
|
5760
5820
|
exports.override = override;
|
|
5821
|
+
exports.ownKeys = apiOwnKeys;
|
|
5761
5822
|
exports.reaction = reaction;
|
|
5762
5823
|
exports.remove = remove;
|
|
5763
5824
|
exports.runInAction = runInAction;
|