mobx 6.16.0 → 6.16.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 +8 -0
- package/dist/mobx.cjs.development.js +27 -7
- 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.esm.development.js +27 -7
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +27 -7
- 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 +27 -7
- 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 +2 -4
- package/src/types/computedannotation.ts +30 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx",
|
|
3
|
-
"version": "6.16.
|
|
3
|
+
"version": "6.16.1",
|
|
4
4
|
"description": "Simple, scalable state management.",
|
|
5
5
|
"source": "src/mobx.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -43,8 +43,7 @@
|
|
|
43
43
|
"@babel/preset-env": "^7.9.5",
|
|
44
44
|
"@babel/preset-typescript": "^7.9.0",
|
|
45
45
|
"@babel/runtime": "^7.9.2",
|
|
46
|
-
"conditional-type-checks": "^1.0.5"
|
|
47
|
-
"flow-bin": "^0.123.0"
|
|
46
|
+
"conditional-type-checks": "^1.0.5"
|
|
48
47
|
},
|
|
49
48
|
"keywords": [
|
|
50
49
|
"mobx",
|
|
@@ -72,7 +71,6 @@
|
|
|
72
71
|
"test:performance": "npm run perf -- proxy && npm run perf -- legacy && npm run perf-decorator",
|
|
73
72
|
"test:mixed-versions": "npm test -- --testRegex mixed-versions",
|
|
74
73
|
"test:types": "tsc --noEmit",
|
|
75
|
-
"test:flow": "flow check",
|
|
76
74
|
"test:coverage": "npm test -- -i --coverage",
|
|
77
75
|
"test:size": "import-size --report . observable computed autorun action",
|
|
78
76
|
"test:check": "npm run test:types",
|
|
@@ -53,28 +53,45 @@ function decorate_20223_(this: Annotation, get, context: ClassGetterDecoratorCon
|
|
|
53
53
|
}
|
|
54
54
|
const ann = this
|
|
55
55
|
const { name: key, addInitializer } = context
|
|
56
|
+
let computedValues: WeakMap<object, ComputedValue<any>> | undefined
|
|
56
57
|
|
|
57
58
|
// Defer ComputedValue creation until first access — avoids allocating
|
|
58
59
|
// ComputedValues for getters that are never read on a given instance.
|
|
59
60
|
// The factory is materialised by ObservableObjectAdministration on demand.
|
|
61
|
+
function createComputedValue(target: object, adm: ObservableObjectAdministration) {
|
|
62
|
+
const options = {
|
|
63
|
+
...ann.options_,
|
|
64
|
+
get,
|
|
65
|
+
context: target
|
|
66
|
+
}
|
|
67
|
+
options.name ||= __DEV__
|
|
68
|
+
? `${adm.name_}.${key.toString()}`
|
|
69
|
+
: `ObservableObject.${key.toString()}`
|
|
70
|
+
return new ComputedValue(options)
|
|
71
|
+
}
|
|
72
|
+
|
|
60
73
|
addInitializer(function () {
|
|
61
74
|
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
|
-
})
|
|
75
|
+
const target = this as object
|
|
76
|
+
const observable = adm.values_.get(key)
|
|
77
|
+
if (observable instanceof ComputedValue && observable.derivation !== get) {
|
|
78
|
+
adm.values_.delete(key)
|
|
79
|
+
}
|
|
80
|
+
;(adm.lazyComputedKeys_ ??= new Map()).set(key, () => createComputedValue(target, adm))
|
|
74
81
|
})
|
|
75
82
|
|
|
76
83
|
return function () {
|
|
77
|
-
|
|
84
|
+
const adm: ObservableObjectAdministration = this[$mobx]
|
|
85
|
+
const observable = adm.values_.get(key)
|
|
86
|
+
if (observable instanceof ComputedValue && observable.derivation !== get) {
|
|
87
|
+
let computed = computedValues?.get(this)
|
|
88
|
+
if (!computed) {
|
|
89
|
+
computed = createComputedValue(this, adm)
|
|
90
|
+
;(computedValues ??= new WeakMap()).set(this, computed)
|
|
91
|
+
}
|
|
92
|
+
return computed.get()
|
|
93
|
+
}
|
|
94
|
+
return adm.getObservablePropValue_(key)
|
|
78
95
|
}
|
|
79
96
|
}
|
|
80
97
|
|