mobx 6.16.0 → 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.
- package/CHANGELOG.md +80 -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 +0 -3
- package/dist/core/computedvalue.d.ts +4 -32
- package/dist/core/derivation.d.ts +1 -7
- package/dist/core/globalstate.d.ts +0 -2
- 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 +1647 -2444
- 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 +1636 -2443
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +1584 -2394
- 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 +5271 -0
- package/dist/mobx.mjs.map +1 -0
- package/dist/mobx.umd.development.js +1650 -2447
- 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 +26 -18
- 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 +14 -13
- package/src/core/computedvalue.ts +27 -67
- package/src/core/derivation.ts +15 -14
- package/src/core/globalstate.ts +8 -13
- package/src/core/observable.ts +0 -48
- 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 +40 -21
- 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/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 +5 -28
- 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/src/errors.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const niceErrors = {
|
|
1
|
+
export const niceErrors = {
|
|
2
2
|
0: `Invalid value for configuration 'enforceActions', expected 'never', 'always' or 'observed'`,
|
|
3
3
|
1(annotationType, key: PropertyKey) {
|
|
4
4
|
return `Cannot apply '${annotationType}' to '${key.toString()}': Field not found.`
|
|
@@ -26,10 +26,6 @@ const niceErrors = {
|
|
|
26
26
|
14: "Intercept handlers should return nothing or a change object",
|
|
27
27
|
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)`,
|
|
28
28
|
16: `Modification exception: the internal structure of an observable array was changed.`,
|
|
29
|
-
17(index, length) {
|
|
30
|
-
return `[mobx.array] Index out of bounds, ${index} is larger than ${length}`
|
|
31
|
-
},
|
|
32
|
-
18: "mobx.map requires Map polyfill for the current browser. Check babel-polyfill or core-js/es6/map.js",
|
|
33
29
|
19(other) {
|
|
34
30
|
return "Cannot initialize from classes that inherit from Map: " + other.constructor.name
|
|
35
31
|
},
|
|
@@ -39,7 +35,6 @@ const niceErrors = {
|
|
|
39
35
|
21(dataStructure) {
|
|
40
36
|
return `Cannot convert to map from '${dataStructure}'`
|
|
41
37
|
},
|
|
42
|
-
22: "mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js",
|
|
43
38
|
23: "It is not possible to get index atoms from arrays",
|
|
44
39
|
24(thing) {
|
|
45
40
|
return "Cannot obtain administration from " + thing
|
|
@@ -72,7 +67,25 @@ const niceErrors = {
|
|
|
72
67
|
return `[mobx] \`observableArray.${method}()\` mutates the array in-place, which is not allowed inside a derivation. Use \`array.slice().${method}()\` instead`
|
|
73
68
|
},
|
|
74
69
|
38: "'ownKeys()' can only be used on observable objects",
|
|
75
|
-
39: "'defineProperty()' can only be used on observable objects"
|
|
70
|
+
39: "'defineProperty()' can only be used on observable objects",
|
|
71
|
+
40(length) {
|
|
72
|
+
return "Out of range: " + length
|
|
73
|
+
},
|
|
74
|
+
41(other) {
|
|
75
|
+
return "Cannot initialize set from " + other
|
|
76
|
+
},
|
|
77
|
+
42(key) {
|
|
78
|
+
return `Invalid index: '${key}'`
|
|
79
|
+
},
|
|
80
|
+
43(annotationType, name, kind) {
|
|
81
|
+
return (
|
|
82
|
+
`Cannot apply '${annotationType}' to '${name}' (kind: ${kind}):` +
|
|
83
|
+
`\n'${annotationType}' can only be used on properties with a function value.`
|
|
84
|
+
)
|
|
85
|
+
},
|
|
86
|
+
44(annotationType) {
|
|
87
|
+
return `'${annotationType}' can only be used with 'makeObservable'`
|
|
88
|
+
}
|
|
76
89
|
} as const
|
|
77
90
|
|
|
78
91
|
const errors: typeof niceErrors = __DEV__ ? niceErrors : ({} as any)
|
|
@@ -84,10 +97,8 @@ export function die(error: string | keyof typeof errors, ...args: any[]): never
|
|
|
84
97
|
throw new Error(`[MobX] ${e}`)
|
|
85
98
|
}
|
|
86
99
|
throw new Error(
|
|
87
|
-
|
|
88
|
-
?
|
|
89
|
-
|
|
90
|
-
}. Find the full error at: https://github.com/mobxjs/mobx/blob/main/packages/mobx/src/errors.ts`
|
|
91
|
-
: `[MobX] ${error}`
|
|
100
|
+
`[MobX] minified error nr: ${error}${
|
|
101
|
+
args.length ? " " + args.map(String).join(",") : ""
|
|
102
|
+
}. See mobx.js.org/errors`
|
|
92
103
|
)
|
|
93
104
|
}
|
package/src/internal.ts
CHANGED
|
@@ -5,8 +5,7 @@ it will cause undefined errors (for example because super classes or local varia
|
|
|
5
5
|
With this file that will still happen,
|
|
6
6
|
but at least in this file we can magically reorder the imports with trial and error until the build succeeds again.
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
9
|
-
export * from "./errors"
|
|
8
|
+
export { die } from "./errors"
|
|
10
9
|
export * from "./utils/utils"
|
|
11
10
|
export * from "./api/decorators"
|
|
12
11
|
export * from "./core/atom"
|
|
@@ -43,7 +42,6 @@ export * from "./api/isobservable"
|
|
|
43
42
|
export * from "./api/object-api"
|
|
44
43
|
export * from "./api/observe"
|
|
45
44
|
export * from "./api/tojs"
|
|
46
|
-
export * from "./api/trace"
|
|
47
45
|
export * from "./api/transaction"
|
|
48
46
|
export * from "./api/when"
|
|
49
47
|
export * from "./types/dynamicobject"
|
|
@@ -54,7 +52,6 @@ export * from "./types/observablearray"
|
|
|
54
52
|
export * from "./types/observablemap"
|
|
55
53
|
export * from "./types/observableset"
|
|
56
54
|
export * from "./types/observableobject"
|
|
57
|
-
export * from "./types/legacyobservablearray"
|
|
58
55
|
export * from "./types/type-utils"
|
|
59
56
|
export * from "./utils/eq"
|
|
60
57
|
export * from "./utils/iterable"
|
package/src/mobx.ts
CHANGED
|
@@ -16,13 +16,14 @@
|
|
|
16
16
|
*
|
|
17
17
|
*/
|
|
18
18
|
import { die } from "./errors"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
19
|
+
if (__DEV__) {
|
|
20
|
+
const g = globalThis as any
|
|
21
|
+
;["Symbol", "Map", "Set", "Proxy"].forEach(m => {
|
|
22
|
+
if (typeof g[m] === "undefined") {
|
|
23
|
+
die(`MobX requires global '${m}' to be available or polyfilled`)
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
26
27
|
|
|
27
28
|
import { spy, getDebugName, $mobx } from "./internal"
|
|
28
29
|
|
|
@@ -38,7 +39,10 @@ export {
|
|
|
38
39
|
spy,
|
|
39
40
|
IComputedValue,
|
|
40
41
|
IEqualsComparer,
|
|
41
|
-
|
|
42
|
+
compareDefault,
|
|
43
|
+
compareIdentity,
|
|
44
|
+
compareStructural,
|
|
45
|
+
compareShallow,
|
|
42
46
|
IEnhancer,
|
|
43
47
|
IInterceptable,
|
|
44
48
|
IInterceptor,
|
|
@@ -72,9 +76,14 @@ export {
|
|
|
72
76
|
IObservableSetInitialValues,
|
|
73
77
|
transaction,
|
|
74
78
|
observable,
|
|
79
|
+
observableRef,
|
|
80
|
+
observableShallow,
|
|
81
|
+
observableDeep,
|
|
82
|
+
observableStruct,
|
|
75
83
|
IObservableFactory,
|
|
76
84
|
CreateObservableOptions,
|
|
77
85
|
computed,
|
|
86
|
+
computedStruct,
|
|
78
87
|
IComputedFactory,
|
|
79
88
|
isObservable,
|
|
80
89
|
isObservableProp,
|
|
@@ -90,6 +99,7 @@ export {
|
|
|
90
99
|
when,
|
|
91
100
|
IWhenOptions,
|
|
92
101
|
action,
|
|
102
|
+
actionBound,
|
|
93
103
|
isAction,
|
|
94
104
|
runInAction,
|
|
95
105
|
IActionFactory,
|
|
@@ -106,13 +116,13 @@ export {
|
|
|
106
116
|
onBecomeObserved,
|
|
107
117
|
onBecomeUnobserved,
|
|
108
118
|
flow,
|
|
119
|
+
flowBound,
|
|
109
120
|
isFlow,
|
|
110
121
|
flowResult,
|
|
111
122
|
CancellablePromise,
|
|
112
123
|
FlowCancellationError,
|
|
113
124
|
isFlowCancellationError,
|
|
114
125
|
toJS,
|
|
115
|
-
trace,
|
|
116
126
|
IObserverTree,
|
|
117
127
|
IDependencyTree,
|
|
118
128
|
getDependencyTree,
|
|
@@ -138,6 +148,7 @@ export {
|
|
|
138
148
|
makeObservable,
|
|
139
149
|
makeAutoObservable,
|
|
140
150
|
autoAction as _autoAction,
|
|
151
|
+
autoActionBound as _autoActionBound,
|
|
141
152
|
AnnotationsMap,
|
|
142
153
|
AnnotationMapEntry,
|
|
143
154
|
override
|
|
@@ -145,7 +156,7 @@ export {
|
|
|
145
156
|
|
|
146
157
|
// Devtools support
|
|
147
158
|
declare const __MOBX_DEVTOOLS_GLOBAL_HOOK__: { injectMobx: (any) => void }
|
|
148
|
-
if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
|
|
159
|
+
if (__DEV__ && typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
|
|
149
160
|
// See: https://github.com/andykog/mobx-devtools/
|
|
150
161
|
__MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx({
|
|
151
162
|
spy,
|
|
@@ -16,8 +16,7 @@ export function createActionAnnotation(name: string, options?: object): Annotati
|
|
|
16
16
|
annotationType_: name,
|
|
17
17
|
options_: options,
|
|
18
18
|
make_,
|
|
19
|
-
extend_
|
|
20
|
-
decorate_20223_
|
|
19
|
+
extend_
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -62,12 +61,12 @@ function extend_(
|
|
|
62
61
|
return adm.defineProperty_(key, actionDescriptor, proxyTrap)
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
function
|
|
64
|
+
export function decorateAction20223_(annotation: Annotation, mthd, context: DecoratorContext) {
|
|
66
65
|
if (__DEV__) {
|
|
67
66
|
assert20223DecoratorType(context, ["method", "field"])
|
|
68
67
|
}
|
|
69
68
|
const { kind, name, addInitializer } = context
|
|
70
|
-
const ann =
|
|
69
|
+
const ann = annotation
|
|
71
70
|
|
|
72
71
|
const _createAction = m =>
|
|
73
72
|
createAction(ann.options_?.name ?? name!.toString(), m, ann.options_?.autoAction ?? false)
|
|
@@ -91,7 +90,7 @@ function decorate_20223_(this: Annotation, mthd, context: DecoratorContext) {
|
|
|
91
90
|
mthd = _createAction(mthd)
|
|
92
91
|
}
|
|
93
92
|
|
|
94
|
-
if (
|
|
93
|
+
if (ann.options_?.bound) {
|
|
95
94
|
addInitializer(function () {
|
|
96
95
|
const self = this as any
|
|
97
96
|
const bound = self[name].bind(self)
|
|
@@ -103,10 +102,7 @@ function decorate_20223_(this: Annotation, mthd, context: DecoratorContext) {
|
|
|
103
102
|
return mthd
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
die(
|
|
107
|
-
`Cannot apply '${ann.annotationType_}' to '${String(name)}' (kind: ${kind}):` +
|
|
108
|
-
`\n'${ann.annotationType_}' can only be used on properties with a function value.`
|
|
109
|
-
)
|
|
105
|
+
die(43, ann.annotationType_, String(name), kind)
|
|
110
106
|
}
|
|
111
107
|
|
|
112
108
|
function assertActionDescriptor(
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ObservableObjectAdministration,
|
|
3
3
|
observable,
|
|
4
|
+
observableRef,
|
|
4
5
|
Annotation,
|
|
5
6
|
defineProperty,
|
|
6
7
|
createAction,
|
|
7
8
|
globalState,
|
|
8
9
|
flow,
|
|
10
|
+
flowBound,
|
|
9
11
|
computed,
|
|
10
12
|
autoAction,
|
|
13
|
+
autoActionBound,
|
|
11
14
|
isGenerator,
|
|
12
15
|
MakeResult,
|
|
13
|
-
die,
|
|
14
16
|
isAction
|
|
15
17
|
} from "../internal"
|
|
16
18
|
|
|
@@ -23,8 +25,7 @@ export function createAutoAnnotation(options?: object): Annotation {
|
|
|
23
25
|
annotationType_: AUTO,
|
|
24
26
|
options_: options,
|
|
25
27
|
make_,
|
|
26
|
-
extend_
|
|
27
|
-
decorate_20223_
|
|
28
|
+
extend_
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -63,16 +64,16 @@ function make_(
|
|
|
63
64
|
// function on proto -> autoAction/flow
|
|
64
65
|
if (source !== adm.target_ && typeof descriptor.value === "function") {
|
|
65
66
|
if (isGenerator(descriptor.value)) {
|
|
66
|
-
const flowAnnotation = this.options_?.autoBind ?
|
|
67
|
+
const flowAnnotation = this.options_?.autoBind ? flowBound : flow
|
|
67
68
|
return flowAnnotation.make_(adm, key, descriptor, source)
|
|
68
69
|
}
|
|
69
|
-
const actionAnnotation = this.options_?.autoBind ?
|
|
70
|
+
const actionAnnotation = this.options_?.autoBind ? autoActionBound : autoAction
|
|
70
71
|
return actionAnnotation.make_(adm, key, descriptor, source)
|
|
71
72
|
}
|
|
72
73
|
// other -> observable
|
|
73
74
|
// Copy props from proto as well, see test:
|
|
74
75
|
// "decorate should work with Object.create"
|
|
75
|
-
let observableAnnotation = this.options_?.deep === false ?
|
|
76
|
+
let observableAnnotation = this.options_?.deep === false ? observableRef : observable
|
|
76
77
|
// if function respect autoBind option
|
|
77
78
|
if (typeof descriptor.value === "function" && this.options_?.autoBind) {
|
|
78
79
|
descriptor.value = descriptor.value.bind(adm.proxy_ ?? adm.target_)
|
|
@@ -107,10 +108,6 @@ function extend_(
|
|
|
107
108
|
if (typeof descriptor.value === "function" && this.options_?.autoBind) {
|
|
108
109
|
descriptor.value = descriptor.value.bind(adm.proxy_ ?? adm.target_)
|
|
109
110
|
}
|
|
110
|
-
let observableAnnotation = this.options_?.deep === false ?
|
|
111
|
+
let observableAnnotation = this.options_?.deep === false ? observableRef : observable
|
|
111
112
|
return observableAnnotation.extend_(adm, key, descriptor, proxyTrap)
|
|
112
113
|
}
|
|
113
|
-
|
|
114
|
-
function decorate_20223_(this: Annotation, desc, context: ClassGetterDecoratorContext) {
|
|
115
|
-
die(`'${this.annotationType_}' cannot be used as a decorator`)
|
|
116
|
-
}
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
assert20223DecoratorType,
|
|
7
7
|
$mobx,
|
|
8
8
|
asObservableObject,
|
|
9
|
-
ComputedValue
|
|
9
|
+
ComputedValue,
|
|
10
|
+
assign
|
|
10
11
|
} from "../internal"
|
|
11
12
|
|
|
12
13
|
export function createComputedAnnotation(name: string, options?: object): Annotation {
|
|
@@ -14,8 +15,7 @@ export function createComputedAnnotation(name: string, options?: object): Annota
|
|
|
14
15
|
annotationType_: name,
|
|
15
16
|
options_: options,
|
|
16
17
|
make_,
|
|
17
|
-
extend_
|
|
18
|
-
decorate_20223_
|
|
18
|
+
extend_
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -38,43 +38,62 @@ function extend_(
|
|
|
38
38
|
assertComputedDescriptor(adm, this, key, descriptor)
|
|
39
39
|
return adm.defineComputedProperty_(
|
|
40
40
|
key,
|
|
41
|
-
{
|
|
42
|
-
...this.options_,
|
|
41
|
+
assign({}, this.options_, {
|
|
43
42
|
get: descriptor.get,
|
|
44
43
|
set: descriptor.set
|
|
45
|
-
},
|
|
44
|
+
}),
|
|
46
45
|
proxyTrap
|
|
47
46
|
)
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
function
|
|
49
|
+
export function decorateComputed20223_(
|
|
50
|
+
annotation: Annotation,
|
|
51
|
+
get,
|
|
52
|
+
context: ClassGetterDecoratorContext
|
|
53
|
+
) {
|
|
51
54
|
if (__DEV__) {
|
|
52
55
|
assert20223DecoratorType(context, ["getter"])
|
|
53
56
|
}
|
|
54
|
-
const ann =
|
|
57
|
+
const ann = annotation
|
|
55
58
|
const { name: key, addInitializer } = context
|
|
59
|
+
let computedValues: WeakMap<object, ComputedValue<any>> | undefined
|
|
56
60
|
|
|
57
61
|
// Defer ComputedValue creation until first access — avoids allocating
|
|
58
62
|
// ComputedValues for getters that are never read on a given instance.
|
|
59
63
|
// The factory is materialised by ObservableObjectAdministration on demand.
|
|
64
|
+
function createComputedValue(target: object, adm: ObservableObjectAdministration) {
|
|
65
|
+
const options = assign({}, ann.options_, {
|
|
66
|
+
get,
|
|
67
|
+
context: target
|
|
68
|
+
})
|
|
69
|
+
options.name ||= __DEV__
|
|
70
|
+
? `${adm.name_}.${key.toString()}`
|
|
71
|
+
: `ObservableObject.${key.toString()}`
|
|
72
|
+
return new ComputedValue(options)
|
|
73
|
+
}
|
|
74
|
+
|
|
60
75
|
addInitializer(function () {
|
|
61
76
|
const adm: ObservableObjectAdministration = asObservableObject(this)[$mobx]
|
|
62
|
-
const target = this
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
options.name ||= __DEV__
|
|
70
|
-
? `${adm.name_}.${key.toString()}`
|
|
71
|
-
: `ObservableObject.${key.toString()}`
|
|
72
|
-
return new ComputedValue(options)
|
|
73
|
-
})
|
|
77
|
+
const target = this as object
|
|
78
|
+
const observable = adm.values_.get(key)
|
|
79
|
+
if (observable instanceof ComputedValue && observable.derivation !== get) {
|
|
80
|
+
adm.values_.delete(key)
|
|
81
|
+
}
|
|
82
|
+
;(adm.lazyComputedKeys_ ??= new Map()).set(key, () => createComputedValue(target, adm))
|
|
74
83
|
})
|
|
75
84
|
|
|
76
85
|
return function () {
|
|
77
|
-
|
|
86
|
+
const adm: ObservableObjectAdministration = this[$mobx]
|
|
87
|
+
const observable = adm.values_.get(key)
|
|
88
|
+
if (observable instanceof ComputedValue && observable.derivation !== get) {
|
|
89
|
+
let computed = computedValues?.get(this)
|
|
90
|
+
if (!computed) {
|
|
91
|
+
computed = createComputedValue(this, adm)
|
|
92
|
+
;(computedValues ??= new WeakMap()).set(this, computed)
|
|
93
|
+
}
|
|
94
|
+
return computed.get()
|
|
95
|
+
}
|
|
96
|
+
return adm.getObservablePropValue_(key)
|
|
78
97
|
}
|
|
79
98
|
}
|
|
80
99
|
|
|
@@ -25,6 +25,10 @@ export type ClassFieldDecorator<This = any, Value extends (...p: any[]) => any =
|
|
|
25
25
|
context: ClassFieldDecoratorContext<This, Value>
|
|
26
26
|
) => Value | void
|
|
27
27
|
|
|
28
|
+
export type ClassMethodAndFieldDecorator = ClassMethodDecorator & ClassFieldDecorator
|
|
29
|
+
|
|
30
|
+
export type ClassAccessorAndFieldDecorator = ClassAccessorDecorator & ClassFieldDecorator
|
|
31
|
+
|
|
28
32
|
export type Decorator =
|
|
29
33
|
| ClassAccessorDecorator
|
|
30
34
|
| ClassGetterDecorator
|
|
@@ -2,11 +2,8 @@ import {
|
|
|
2
2
|
$mobx,
|
|
3
3
|
IIsObservableObject,
|
|
4
4
|
ObservableObjectAdministration,
|
|
5
|
-
warnAboutProxyRequirement,
|
|
6
|
-
assertProxies,
|
|
7
5
|
die,
|
|
8
6
|
isStringish,
|
|
9
|
-
globalState,
|
|
10
7
|
CreateObservableOptions,
|
|
11
8
|
asObservableObject
|
|
12
9
|
} from "../internal"
|
|
@@ -19,11 +16,6 @@ function getAdm(target): ObservableObjectAdministration {
|
|
|
19
16
|
// and skip either the internal values map, or the base object with its property descriptors!
|
|
20
17
|
const objectProxyTraps: ProxyHandler<any> = {
|
|
21
18
|
has(target: IIsObservableObject, name: PropertyKey): boolean {
|
|
22
|
-
if (__DEV__ && globalState.trackingDerivation) {
|
|
23
|
-
warnAboutProxyRequirement(
|
|
24
|
-
"detect new properties using the 'in' operator. Use 'has' from 'mobx' instead."
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
19
|
return getAdm(target).has_(name)
|
|
28
20
|
},
|
|
29
21
|
get(target: IIsObservableObject, name: PropertyKey): any {
|
|
@@ -33,20 +25,10 @@ const objectProxyTraps: ProxyHandler<any> = {
|
|
|
33
25
|
if (!isStringish(name)) {
|
|
34
26
|
return false
|
|
35
27
|
}
|
|
36
|
-
if (__DEV__ && !getAdm(target).values_.has(name)) {
|
|
37
|
-
warnAboutProxyRequirement(
|
|
38
|
-
"add a new observable property through direct assignment. Use 'set' from 'mobx' instead."
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
28
|
// null (intercepted) -> true (success)
|
|
42
29
|
return getAdm(target).set_(name, value, true) ?? true
|
|
43
30
|
},
|
|
44
31
|
deleteProperty(target: IIsObservableObject, name: PropertyKey): boolean {
|
|
45
|
-
if (__DEV__) {
|
|
46
|
-
warnAboutProxyRequirement(
|
|
47
|
-
"delete properties from an observable object. Use 'remove' from 'mobx' instead."
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
32
|
if (!isStringish(name)) {
|
|
51
33
|
return false
|
|
52
34
|
}
|
|
@@ -58,20 +40,10 @@ const objectProxyTraps: ProxyHandler<any> = {
|
|
|
58
40
|
name: PropertyKey,
|
|
59
41
|
descriptor: PropertyDescriptor
|
|
60
42
|
): boolean {
|
|
61
|
-
if (__DEV__) {
|
|
62
|
-
warnAboutProxyRequirement(
|
|
63
|
-
"define property on an observable object. Use 'defineProperty' from 'mobx' instead."
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
43
|
// null (intercepted) -> true (success)
|
|
67
44
|
return getAdm(target).defineProperty_(name, descriptor) ?? true
|
|
68
45
|
},
|
|
69
46
|
ownKeys(target: IIsObservableObject): ArrayLike<string | symbol> {
|
|
70
|
-
if (__DEV__ && globalState.trackingDerivation) {
|
|
71
|
-
warnAboutProxyRequirement(
|
|
72
|
-
"iterate keys to detect added / removed properties. Use 'keys' from 'mobx' instead."
|
|
73
|
-
)
|
|
74
|
-
}
|
|
75
47
|
return getAdm(target).ownKeys_()
|
|
76
48
|
},
|
|
77
49
|
preventExtensions(target) {
|
|
@@ -83,7 +55,6 @@ export function asDynamicObservableObject(
|
|
|
83
55
|
target: any,
|
|
84
56
|
options?: CreateObservableOptions
|
|
85
57
|
): IIsObservableObject {
|
|
86
|
-
assertProxies()
|
|
87
58
|
target = asObservableObject(target, options)
|
|
88
59
|
return (target[$mobx].proxy_ ??= new Proxy(target, objectProxyTraps))
|
|
89
60
|
}
|
|
@@ -17,8 +17,7 @@ export function createFlowAnnotation(name: string, options?: object): Annotation
|
|
|
17
17
|
annotationType_: name,
|
|
18
18
|
options_: options,
|
|
19
19
|
make_,
|
|
20
|
-
extend_
|
|
21
|
-
decorate_20223_
|
|
20
|
+
extend_
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -63,7 +62,11 @@ function extend_(
|
|
|
63
62
|
return adm.defineProperty_(key, flowDescriptor, proxyTrap)
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
function
|
|
65
|
+
export function decorateFlow20223_(
|
|
66
|
+
annotation: Annotation,
|
|
67
|
+
mthd,
|
|
68
|
+
context: ClassMethodDecoratorContext
|
|
69
|
+
) {
|
|
67
70
|
if (__DEV__) {
|
|
68
71
|
assert20223DecoratorType(context, ["method"])
|
|
69
72
|
}
|
|
@@ -73,7 +76,7 @@ function decorate_20223_(this: Annotation, mthd, context: ClassMethodDecoratorCo
|
|
|
73
76
|
mthd = flow(mthd)
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
if (
|
|
79
|
+
if (annotation.options_?.bound) {
|
|
77
80
|
addInitializer(function () {
|
|
78
81
|
const self = this as any
|
|
79
82
|
const bound = self[name].bind(self)
|
|
@@ -15,8 +15,7 @@ export function createObservableAnnotation(name: string, options?: object): Anno
|
|
|
15
15
|
annotationType_: name,
|
|
16
16
|
options_: options,
|
|
17
17
|
make_,
|
|
18
|
-
extend_
|
|
19
|
-
decorate_20223_
|
|
18
|
+
extend_
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
|
|
@@ -40,13 +39,13 @@ function extend_(
|
|
|
40
39
|
return adm.defineObservableProperty_(
|
|
41
40
|
key,
|
|
42
41
|
descriptor.value,
|
|
43
|
-
this.options_?.
|
|
42
|
+
this.options_?.enhancer_ ?? deepEnhancer,
|
|
44
43
|
proxyTrap
|
|
45
44
|
)
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
function
|
|
49
|
-
|
|
47
|
+
export function decorateObservable20223_(
|
|
48
|
+
annotation: Annotation,
|
|
50
49
|
desc,
|
|
51
50
|
context: ClassAccessorDecoratorContext | ClassFieldDecoratorContext
|
|
52
51
|
) {
|
|
@@ -61,7 +60,7 @@ function decorate_20223_(
|
|
|
61
60
|
assert20223DecoratorType(context, ["accessor"])
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
const ann =
|
|
63
|
+
const ann = annotation
|
|
65
64
|
const { kind, name } = context
|
|
66
65
|
|
|
67
66
|
if (kind !== "accessor") {
|
|
@@ -78,7 +77,7 @@ function decorate_20223_(
|
|
|
78
77
|
() =>
|
|
79
78
|
new ObservableValue(
|
|
80
79
|
value,
|
|
81
|
-
ann.options_?.
|
|
80
|
+
ann.options_?.enhancer_ ?? deepEnhancer,
|
|
82
81
|
__DEV__
|
|
83
82
|
? `${adm.name_}.${name.toString()}`
|
|
84
83
|
: `ObservableObject.${name.toString()}`,
|