mobx 6.3.9 → 6.3.13
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 +24 -0
- package/dist/api/tojs.d.ts +4 -1
- package/dist/mobx.cjs.development.js +55 -41
- 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 +55 -41
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +55 -41
- 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 +55 -41
- 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/tojs.ts +4 -1
- package/src/types/flowannotation.ts +11 -3
- package/src/types/observablemap.ts +5 -2
- package/src/utils/eq.ts +1 -1
package/package.json
CHANGED
package/src/api/tojs.ts
CHANGED
|
@@ -62,7 +62,10 @@ function toJSHelper(source, __alreadySeen: Map<any, any>) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* Recursively converts an observable to it's non-observable native counterpart.
|
|
66
|
+
* It does NOT recurse into non-observables, these are left as they are, even if they contain observables.
|
|
67
|
+
* Computed and other non-enumerable properties are completely ignored.
|
|
68
|
+
* Complex scenarios require custom solution, eg implementing `toJSON` or using `serializr` lib.
|
|
66
69
|
*/
|
|
67
70
|
export function toJS<T>(source: T, options?: any): T {
|
|
68
71
|
if (__DEV__ && options) die("toJS no longer supports options")
|
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
isFlow,
|
|
8
8
|
isFunction,
|
|
9
9
|
globalState,
|
|
10
|
-
MakeResult
|
|
10
|
+
MakeResult,
|
|
11
|
+
hasProp
|
|
11
12
|
} from "../internal"
|
|
12
13
|
|
|
13
14
|
export function createFlowAnnotation(name: string, options?: object): Annotation {
|
|
@@ -33,7 +34,7 @@ function make_(
|
|
|
33
34
|
}
|
|
34
35
|
// prototype
|
|
35
36
|
// bound - must annotate protos to support super.flow()
|
|
36
|
-
if (this.options_?.bound && !isFlow(adm.target_[key])) {
|
|
37
|
+
if (this.options_?.bound && (!hasProp(adm.target_, key) || !isFlow(adm.target_[key]))) {
|
|
37
38
|
if (this.extend_(adm, key, descriptor, false) === null) return MakeResult.Cancel
|
|
38
39
|
}
|
|
39
40
|
if (isFlow(descriptor.value)) {
|
|
@@ -81,11 +82,18 @@ function createFlowDescriptor(
|
|
|
81
82
|
): PropertyDescriptor {
|
|
82
83
|
assertFlowDescriptor(adm, annotation, key, descriptor)
|
|
83
84
|
let { value } = descriptor
|
|
85
|
+
// In case of flow.bound, the descriptor can be from already annotated prototype
|
|
86
|
+
if (!isFlow(value)) {
|
|
87
|
+
value = flow(value)
|
|
88
|
+
}
|
|
84
89
|
if (bound) {
|
|
90
|
+
// We do not keep original function around, so we bind the existing flow
|
|
85
91
|
value = value.bind(adm.proxy_ ?? adm.target_)
|
|
92
|
+
// This is normally set by `flow`, but `bind` returns new function...
|
|
93
|
+
value.isMobXFlow = true
|
|
86
94
|
}
|
|
87
95
|
return {
|
|
88
|
-
value
|
|
96
|
+
value,
|
|
89
97
|
// Non-configurable for classes
|
|
90
98
|
// prevents accidental field redefinition in subclass
|
|
91
99
|
configurable: safeDescriptors ? adm.isPlainObject_ : true,
|
|
@@ -34,7 +34,8 @@ import {
|
|
|
34
34
|
isFunction,
|
|
35
35
|
UPDATE,
|
|
36
36
|
IAtom,
|
|
37
|
-
PureSpyEvent
|
|
37
|
+
PureSpyEvent,
|
|
38
|
+
allowStateChanges
|
|
38
39
|
} from "../internal"
|
|
39
40
|
|
|
40
41
|
export interface IKeyValueMap<V = any> {
|
|
@@ -107,7 +108,9 @@ export class ObservableMap<K = any, V = any>
|
|
|
107
108
|
this.keysAtom_ = createAtom(__DEV__ ? `${this.name_}.keys()` : "ObservableMap.keys()")
|
|
108
109
|
this.data_ = new Map()
|
|
109
110
|
this.hasMap_ = new Map()
|
|
110
|
-
|
|
111
|
+
allowStateChanges(true, () => {
|
|
112
|
+
this.merge(initialData)
|
|
113
|
+
})
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
private has_(key: K): boolean {
|
package/src/utils/eq.ts
CHANGED
|
@@ -28,7 +28,7 @@ function eq(a: any, b: any, depth: number, aStack?: any[], bStack?: any[]) {
|
|
|
28
28
|
if (a !== a) return b !== b
|
|
29
29
|
// Exhaust primitive checks
|
|
30
30
|
const type = typeof a
|
|
31
|
-
if (
|
|
31
|
+
if (type !== "function" && type !== "object" && typeof b != "object") return false
|
|
32
32
|
|
|
33
33
|
// Compare `[[Class]]` names.
|
|
34
34
|
const className = toString.call(a)
|