mobx 6.1.4 → 6.1.8
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 +35 -0
- package/dist/api/annotation.d.ts +0 -1
- package/dist/api/iscomputed.d.ts +2 -2
- package/dist/core/computedvalue.d.ts +0 -1
- package/dist/core/derivation.d.ts +0 -1
- package/dist/core/reaction.d.ts +0 -1
- package/dist/mobx.cjs.development.js +92 -46
- 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 +92 -46
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +92 -46
- 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 +92 -46
- 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/observablearray.d.ts +1 -1
- package/dist/types/type-utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/api/annotation.ts +0 -1
- package/src/api/autorun.ts +3 -2
- package/src/api/computed.ts +1 -1
- package/src/api/decorators.ts +1 -4
- package/src/api/iscomputed.ts +2 -2
- package/src/api/makeObservable.ts +10 -2
- package/src/api/observable.ts +1 -1
- package/src/api/when.ts +5 -2
- package/src/core/atom.ts +1 -1
- package/src/core/computedvalue.ts +7 -3
- package/src/core/derivation.ts +0 -1
- package/src/core/reaction.ts +1 -2
- package/src/types/actionannotation.ts +3 -2
- package/src/types/computedannotation.ts +3 -2
- package/src/types/flowannotation.ts +3 -2
- package/src/types/legacyobservablearray.ts +1 -1
- package/src/types/observableannotation.ts +3 -2
- package/src/types/observablearray.ts +5 -4
- package/src/types/observablemap.ts +4 -4
- package/src/types/observableobject.ts +27 -14
- package/src/types/observableset.ts +1 -1
- package/src/types/observablevalue.ts +1 -1
- package/src/types/type-utils.ts +11 -4
- package/src/utils/global.ts +3 -0
|
@@ -51,7 +51,7 @@ export declare class ObservableArrayAdministration implements IInterceptable<IAr
|
|
|
51
51
|
dehancer: any;
|
|
52
52
|
proxy_: IObservableArray<any>;
|
|
53
53
|
lastKnownLength_: number;
|
|
54
|
-
constructor(name:
|
|
54
|
+
constructor(name: string | undefined, enhancer: IEnhancer<any>, owned_: boolean, legacyMode_: boolean);
|
|
55
55
|
dehanceValue_(value: any): any;
|
|
56
56
|
dehanceValues_(values: any[]): any[];
|
|
57
57
|
intercept_(handler: IInterceptor<IArrayWillChange<any> | IArrayWillSplice<any>>): Lambda;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IDepTreeNode } from "../internal";
|
|
2
|
-
export declare function getAtom(thing: any, property?:
|
|
2
|
+
export declare function getAtom(thing: any, property?: PropertyKey): IDepTreeNode;
|
|
3
3
|
export declare function getAdministration(thing: any, property?: string): any;
|
|
4
4
|
export declare function getDebugName(thing: any, property?: string): string;
|
package/package.json
CHANGED
package/src/api/annotation.ts
CHANGED
package/src/api/autorun.ts
CHANGED
|
@@ -42,7 +42,8 @@ export function autorun(
|
|
|
42
42
|
if (isAction(view)) die("Autorun does not accept actions since actions are untrackable")
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const name: string =
|
|
45
|
+
const name: string =
|
|
46
|
+
opts?.name ?? (__DEV__ ? (view as any).name || "Autorun@" + getNextId() : "Autorun")
|
|
46
47
|
const runSync = !opts.scheduler && !opts.delay
|
|
47
48
|
let reaction: Reaction
|
|
48
49
|
|
|
@@ -110,7 +111,7 @@ export function reaction<T>(
|
|
|
110
111
|
die("First and second argument to reaction should be functions")
|
|
111
112
|
if (!isPlainObject(opts)) die("Third argument of reactions should be an object")
|
|
112
113
|
}
|
|
113
|
-
const name = opts.name
|
|
114
|
+
const name = opts.name ?? (__DEV__ ? "Reaction@" + getNextId() : "Reaction")
|
|
114
115
|
const effectAction = action(
|
|
115
116
|
name,
|
|
116
117
|
opts.onError ? wrapErrorHandler(opts.onError, effect) : effect
|
package/src/api/computed.ts
CHANGED
|
@@ -54,7 +54,7 @@ export const computed: IComputedFactory = function computed(arg1, arg2) {
|
|
|
54
54
|
}
|
|
55
55
|
const opts: IComputedValueOptions<any> = isPlainObject(arg2) ? arg2 : {}
|
|
56
56
|
opts.get = arg1
|
|
57
|
-
opts.name
|
|
57
|
+
opts.name ||= arg1.name || "" /* for generated name */
|
|
58
58
|
|
|
59
59
|
return new ComputedValue(opts)
|
|
60
60
|
} as any
|
package/src/api/decorators.ts
CHANGED
|
@@ -38,10 +38,7 @@ export function storeAnnotation(prototype: any, key: PropertyKey, annotation: An
|
|
|
38
38
|
|
|
39
39
|
// Ignore override
|
|
40
40
|
if (!isOverride(annotation)) {
|
|
41
|
-
prototype[storedAnnotationsSymbol][key] =
|
|
42
|
-
...annotation,
|
|
43
|
-
isDecorator_: true
|
|
44
|
-
}
|
|
41
|
+
prototype[storedAnnotationsSymbol][key] = annotation
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
|
package/src/api/iscomputed.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { $mobx, getAtom, isComputedValue, isObservableObject, die, isStringish } from "../internal"
|
|
2
2
|
|
|
3
|
-
export function _isComputed(value, property?:
|
|
3
|
+
export function _isComputed(value, property?: PropertyKey): boolean {
|
|
4
4
|
if (property !== undefined) {
|
|
5
5
|
if (isObservableObject(value) === false) return false
|
|
6
6
|
if (!value[$mobx].values_.has(property)) return false
|
|
@@ -18,7 +18,7 @@ export function isComputed(value: any): boolean {
|
|
|
18
18
|
return _isComputed(value)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function isComputedProp(value: any, propName:
|
|
21
|
+
export function isComputedProp(value: any, propName: PropertyKey): boolean {
|
|
22
22
|
if (__DEV__ && !isStringish(propName))
|
|
23
23
|
return die(`isComputed expected a property name as second argument`)
|
|
24
24
|
return _isComputed(value, propName)
|
|
@@ -63,9 +63,17 @@ export function makeAutoObservable<T extends object, AdditionalKeys extends Prop
|
|
|
63
63
|
const adm: ObservableObjectAdministration = asObservableObject(target, options)[$mobx]
|
|
64
64
|
startBatch()
|
|
65
65
|
try {
|
|
66
|
+
// Use cached inferred annotations if available (only in classes)
|
|
66
67
|
if (target[inferredAnnotationsSymbol]) {
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
target[inferredAnnotationsSymbol].forEach((value, key) => adm.make_(key, value))
|
|
69
|
+
// Overrides are not cached, unless `true`, see #2832
|
|
70
|
+
if (overrides) {
|
|
71
|
+
ownKeys(overrides).forEach(key => {
|
|
72
|
+
const annotation = overrides[key]
|
|
73
|
+
if (annotation !== true) {
|
|
74
|
+
adm.make_(key, annotation)
|
|
75
|
+
}
|
|
76
|
+
})
|
|
69
77
|
}
|
|
70
78
|
} else {
|
|
71
79
|
const ignoreKeys = { [$mobx]: 1, [inferredAnnotationsSymbol]: 1, constructor: 1 }
|
package/src/api/observable.ts
CHANGED
|
@@ -125,7 +125,7 @@ function createObservable(v: any, arg2?: any, arg3?: any) {
|
|
|
125
125
|
if (typeof v === "object" && v !== null) return v
|
|
126
126
|
|
|
127
127
|
// anything else
|
|
128
|
-
return observable.box(v)
|
|
128
|
+
return observable.box(v, arg2)
|
|
129
129
|
}
|
|
130
130
|
Object.assign(createObservable, observableDecoratorAnnotation)
|
|
131
131
|
|
package/src/api/when.ts
CHANGED
|
@@ -43,8 +43,11 @@ function _when(predicate: () => boolean, effect: Lambda, opts: IWhenOptions): IR
|
|
|
43
43
|
}, opts.timeout)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
opts.name = opts.name || "When@" + getNextId()
|
|
47
|
-
const effectAction = createAction(
|
|
46
|
+
opts.name = __DEV__ ? opts.name || "When@" + getNextId() : "When"
|
|
47
|
+
const effectAction = createAction(
|
|
48
|
+
__DEV__ ? opts.name + "-effect" : "When-effect",
|
|
49
|
+
effect as Function
|
|
50
|
+
)
|
|
48
51
|
// eslint-disable-next-line
|
|
49
52
|
var disposer = autorun(r => {
|
|
50
53
|
// predicate should not change state
|
package/src/core/atom.ts
CHANGED
|
@@ -33,7 +33,7 @@ export class Atom implements IAtom {
|
|
|
33
33
|
* Create a new atom. For debugging purposes it is recommended to give it a name.
|
|
34
34
|
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
|
|
35
35
|
*/
|
|
36
|
-
constructor(public name_ = "Atom@" + getNextId()) {}
|
|
36
|
+
constructor(public name_ = __DEV__ ? "Atom@" + getNextId() : "Atom") {}
|
|
37
37
|
|
|
38
38
|
// onBecomeObservedListeners
|
|
39
39
|
public onBOL: Set<Lambda> | undefined
|
|
@@ -88,7 +88,6 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva
|
|
|
88
88
|
lastAccessedBy_ = 0
|
|
89
89
|
lowestObserverState_ = IDerivationState_.UP_TO_DATE_
|
|
90
90
|
unboundDepsCount_ = 0
|
|
91
|
-
mapid_ = "#" + getNextId()
|
|
92
91
|
protected value_: T | undefined | CaughtException = new CaughtException(null)
|
|
93
92
|
name_: string
|
|
94
93
|
triggeredBy_?: string
|
|
@@ -117,8 +116,13 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva
|
|
|
117
116
|
constructor(options: IComputedValueOptions<T>) {
|
|
118
117
|
if (!options.get) die(31)
|
|
119
118
|
this.derivation = options.get!
|
|
120
|
-
this.name_ = options.name || "ComputedValue@" + getNextId()
|
|
121
|
-
if (options.set)
|
|
119
|
+
this.name_ = options.name || (__DEV__ ? "ComputedValue@" + getNextId() : "ComputedValue")
|
|
120
|
+
if (options.set) {
|
|
121
|
+
this.setter_ = createAction(
|
|
122
|
+
__DEV__ ? this.name_ + "-setter" : "ComputedValue-setter",
|
|
123
|
+
options.set
|
|
124
|
+
) as any
|
|
125
|
+
}
|
|
122
126
|
this.equals_ =
|
|
123
127
|
options.equals ||
|
|
124
128
|
((options as any).compareStructural || (options as any).struct
|
package/src/core/derivation.ts
CHANGED
package/src/core/reaction.ts
CHANGED
|
@@ -57,7 +57,6 @@ export class Reaction implements IDerivation, IReactionPublic {
|
|
|
57
57
|
diffValue_ = 0
|
|
58
58
|
runId_ = 0
|
|
59
59
|
unboundDepsCount_ = 0
|
|
60
|
-
mapid_ = "#" + getNextId()
|
|
61
60
|
isDisposed_ = false
|
|
62
61
|
isScheduled_ = false
|
|
63
62
|
isTrackPending_ = false
|
|
@@ -65,7 +64,7 @@ export class Reaction implements IDerivation, IReactionPublic {
|
|
|
65
64
|
isTracing_: TraceMode = TraceMode.NONE
|
|
66
65
|
|
|
67
66
|
constructor(
|
|
68
|
-
public name_: string = "Reaction@" + getNextId(),
|
|
67
|
+
public name_: string = __DEV__ ? "Reaction@" + getNextId() : "Reaction",
|
|
69
68
|
private onInvalidate_: () => void,
|
|
70
69
|
private errorHandler_?: (error: any, derivation: IDerivation) => void,
|
|
71
70
|
public requiresObservable_ = false
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
isFunction,
|
|
10
10
|
Annotation,
|
|
11
11
|
recordAnnotationApplied,
|
|
12
|
-
globalState
|
|
12
|
+
globalState,
|
|
13
|
+
storedAnnotationsSymbol
|
|
13
14
|
} from "../internal"
|
|
14
15
|
|
|
15
16
|
export function createActionAnnotation(name: string, options?: object): Annotation {
|
|
@@ -61,7 +62,7 @@ function make_(adm: ObservableObjectAdministration, key: PropertyKey): void {
|
|
|
61
62
|
}
|
|
62
63
|
if (annotated) {
|
|
63
64
|
recordAnnotationApplied(adm, this, key)
|
|
64
|
-
} else if (!
|
|
65
|
+
} else if (!adm.target_[storedAnnotationsSymbol]?.[key]) {
|
|
65
66
|
// Throw on missing key, except for decorators:
|
|
66
67
|
// Decorator annotations are collected from whole prototype chain.
|
|
67
68
|
// When called from super() some props may not exist yet.
|
|
@@ -4,7 +4,8 @@ import {
|
|
|
4
4
|
objectPrototype,
|
|
5
5
|
die,
|
|
6
6
|
Annotation,
|
|
7
|
-
recordAnnotationApplied
|
|
7
|
+
recordAnnotationApplied,
|
|
8
|
+
storedAnnotationsSymbol
|
|
8
9
|
} from "../internal"
|
|
9
10
|
|
|
10
11
|
export function createComputedAnnotation(name: string, options?: object): Annotation {
|
|
@@ -36,7 +37,7 @@ function make_(adm: ObservableObjectAdministration, key: PropertyKey): void {
|
|
|
36
37
|
}
|
|
37
38
|
source = Object.getPrototypeOf(source)
|
|
38
39
|
}
|
|
39
|
-
if (!
|
|
40
|
+
if (!adm.target_[storedAnnotationsSymbol]?.[key]) {
|
|
40
41
|
// Throw on missing key, except for decorators:
|
|
41
42
|
// Decorator annotations are collected from whole prototype chain.
|
|
42
43
|
// When called from super() some props may not exist yet.
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
isFlow,
|
|
10
10
|
recordAnnotationApplied,
|
|
11
11
|
isFunction,
|
|
12
|
-
globalState
|
|
12
|
+
globalState,
|
|
13
|
+
storedAnnotationsSymbol
|
|
13
14
|
} from "../internal"
|
|
14
15
|
|
|
15
16
|
export function createFlowAnnotation(name: string, options?: object): Annotation {
|
|
@@ -51,7 +52,7 @@ function make_(adm: ObservableObjectAdministration, key: PropertyKey): void {
|
|
|
51
52
|
}
|
|
52
53
|
if (annotated) {
|
|
53
54
|
recordAnnotationApplied(adm, this, key)
|
|
54
|
-
} else if (!
|
|
55
|
+
} else if (!adm.target_[storedAnnotationsSymbol]?.[key]) {
|
|
55
56
|
// Throw on missing key, except for decorators:
|
|
56
57
|
// Decorator annotations are collected from whole prototype chain.
|
|
57
58
|
// When called from super() some props may not exist yet.
|
|
@@ -42,7 +42,7 @@ class LegacyObservableArray<T> extends StubArray {
|
|
|
42
42
|
constructor(
|
|
43
43
|
initialValues: T[] | undefined,
|
|
44
44
|
enhancer: IEnhancer<T>,
|
|
45
|
-
name = "ObservableArray@" + getNextId(),
|
|
45
|
+
name = __DEV__ ? "ObservableArray@" + getNextId() : "ObservableArray",
|
|
46
46
|
owned = false
|
|
47
47
|
) {
|
|
48
48
|
super()
|
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
die,
|
|
6
6
|
Annotation,
|
|
7
7
|
recordAnnotationApplied,
|
|
8
|
-
objectPrototype
|
|
8
|
+
objectPrototype,
|
|
9
|
+
storedAnnotationsSymbol
|
|
9
10
|
} from "../internal"
|
|
10
11
|
|
|
11
12
|
export function createObservableAnnotation(name: string, options?: object): Annotation {
|
|
@@ -39,7 +40,7 @@ function make_(adm: ObservableObjectAdministration, key: PropertyKey): void {
|
|
|
39
40
|
}
|
|
40
41
|
source = Object.getPrototypeOf(source)
|
|
41
42
|
}
|
|
42
|
-
if (!
|
|
43
|
+
if (!adm.target_[storedAnnotationsSymbol]?.[key]) {
|
|
43
44
|
// Throw on missing key, except for decorators:
|
|
44
45
|
// Decorator annotations are collected from whole prototype chain.
|
|
45
46
|
// When called from super() some props may not exist yet.
|
|
@@ -124,13 +124,14 @@ export class ObservableArrayAdministration
|
|
|
124
124
|
lastKnownLength_ = 0
|
|
125
125
|
|
|
126
126
|
constructor(
|
|
127
|
-
name,
|
|
127
|
+
name = __DEV__ ? "ObservableArray@" + getNextId() : "ObservableArray",
|
|
128
128
|
enhancer: IEnhancer<any>,
|
|
129
129
|
public owned_: boolean,
|
|
130
130
|
public legacyMode_: boolean
|
|
131
131
|
) {
|
|
132
|
-
this.atom_ = new Atom(name
|
|
133
|
-
this.enhancer_ = (newV, oldV) =>
|
|
132
|
+
this.atom_ = new Atom(name)
|
|
133
|
+
this.enhancer_ = (newV, oldV) =>
|
|
134
|
+
enhancer(newV, oldV, __DEV__ ? name + "[..]" : "ObservableArray[..]")
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
dehanceValue_(value: any): any {
|
|
@@ -340,7 +341,7 @@ export class ObservableArrayAdministration
|
|
|
340
341
|
export function createObservableArray<T>(
|
|
341
342
|
initialValues: T[] | undefined,
|
|
342
343
|
enhancer: IEnhancer<T>,
|
|
343
|
-
name = "ObservableArray@" + getNextId(),
|
|
344
|
+
name = __DEV__ ? "ObservableArray@" + getNextId() : "ObservableArray",
|
|
344
345
|
owned = false
|
|
345
346
|
): IObservableArray<T> {
|
|
346
347
|
assertProxies()
|
|
@@ -97,12 +97,12 @@ export class ObservableMap<K = any, V = any>
|
|
|
97
97
|
constructor(
|
|
98
98
|
initialData?: IObservableMapInitialValues<K, V>,
|
|
99
99
|
public enhancer_: IEnhancer<V> = deepEnhancer,
|
|
100
|
-
public name_ = "ObservableMap@" + getNextId()
|
|
100
|
+
public name_ = __DEV__ ? "ObservableMap@" + getNextId() : "ObservableMap"
|
|
101
101
|
) {
|
|
102
102
|
if (!isFunction(Map)) {
|
|
103
103
|
die(18)
|
|
104
104
|
}
|
|
105
|
-
this.keysAtom_ = createAtom(`${this.name_}.keys()`)
|
|
105
|
+
this.keysAtom_ = createAtom(__DEV__ ? `${this.name_}.keys()` : "ObservableMap.keys()")
|
|
106
106
|
this.data_ = new Map()
|
|
107
107
|
this.hasMap_ = new Map()
|
|
108
108
|
this.merge(initialData)
|
|
@@ -120,7 +120,7 @@ export class ObservableMap<K = any, V = any>
|
|
|
120
120
|
const newEntry = (entry = new ObservableValue(
|
|
121
121
|
this.has_(key),
|
|
122
122
|
referenceEnhancer,
|
|
123
|
-
`${this.name_}.${stringifyKey(key)}
|
|
123
|
+
__DEV__ ? `${this.name_}.${stringifyKey(key)}?` : "ObservableMap.key?",
|
|
124
124
|
false
|
|
125
125
|
))
|
|
126
126
|
this.hasMap_.set(key, newEntry)
|
|
@@ -228,7 +228,7 @@ export class ObservableMap<K = any, V = any>
|
|
|
228
228
|
const observable = new ObservableValue(
|
|
229
229
|
newValue,
|
|
230
230
|
this.enhancer_,
|
|
231
|
-
`${this.name_}.${stringifyKey(key)}
|
|
231
|
+
__DEV__ ? `${this.name_}.${stringifyKey(key)}` : "ObservableMap.key",
|
|
232
232
|
false
|
|
233
233
|
)
|
|
234
234
|
this.data_.set(key, observable)
|
|
@@ -44,10 +44,12 @@ import {
|
|
|
44
44
|
isOverride,
|
|
45
45
|
defineProperty,
|
|
46
46
|
inferAnnotationFromDescriptor,
|
|
47
|
+
getDebugName,
|
|
48
|
+
getAdministration,
|
|
47
49
|
objectPrototype
|
|
48
50
|
} from "../internal"
|
|
49
51
|
|
|
50
|
-
//
|
|
52
|
+
// closestPrototypeofTarget[inferredAnnotationsSymbol] = new Map<PropertyKes, Annotation>()
|
|
51
53
|
export const inferredAnnotationsSymbol = Symbol("mobx-inferred-annotations")
|
|
52
54
|
|
|
53
55
|
const descriptorCache = Object.create(null)
|
|
@@ -107,7 +109,7 @@ export class ObservableObjectAdministration
|
|
|
107
109
|
// Bind automatically inferred actions?
|
|
108
110
|
public autoBind_: boolean = false
|
|
109
111
|
) {
|
|
110
|
-
this.keysAtom_ = new Atom(name_
|
|
112
|
+
this.keysAtom_ = new Atom(__DEV__ ? `${this.name_}.keys` : "ObservableObject.keys")
|
|
111
113
|
// Optimization: we use this frequently
|
|
112
114
|
this.isPlainObject_ = isPlainObject(this.target_)
|
|
113
115
|
if (__DEV__ && !isAnnotation(this.defaultAnnotation_)) {
|
|
@@ -224,7 +226,7 @@ export class ObservableObjectAdministration
|
|
|
224
226
|
entry = new ObservableValue(
|
|
225
227
|
key in this.target_,
|
|
226
228
|
referenceEnhancer,
|
|
227
|
-
`${this.name_}.${stringifyKey(key)}
|
|
229
|
+
__DEV__ ? `${this.name_}.${stringifyKey(key)}?` : "ObservableObject.key?",
|
|
228
230
|
false
|
|
229
231
|
)
|
|
230
232
|
this.pendingKeys_.set(key, entry)
|
|
@@ -280,7 +282,7 @@ export class ObservableObjectAdministration
|
|
|
280
282
|
|
|
281
283
|
inferAnnotation_(key: PropertyKey): Annotation | false {
|
|
282
284
|
// Inherited is fine - annotation cannot differ in subclass
|
|
283
|
-
let annotation = this.target_[inferredAnnotationsSymbol]?.
|
|
285
|
+
let annotation = this.target_[inferredAnnotationsSymbol]?.get(key)
|
|
284
286
|
if (annotation) return annotation
|
|
285
287
|
|
|
286
288
|
let current = this.target_
|
|
@@ -308,9 +310,9 @@ export class ObservableObjectAdministration
|
|
|
308
310
|
// We could also place it on furthest proto, shoudn't matter
|
|
309
311
|
const closestProto = Object.getPrototypeOf(this.target_)
|
|
310
312
|
if (!hasProp(closestProto, inferredAnnotationsSymbol)) {
|
|
311
|
-
addHiddenProp(closestProto, inferredAnnotationsSymbol,
|
|
313
|
+
addHiddenProp(closestProto, inferredAnnotationsSymbol, new Map())
|
|
312
314
|
}
|
|
313
|
-
closestProto[inferredAnnotationsSymbol]
|
|
315
|
+
closestProto[inferredAnnotationsSymbol].set(key, annotation)
|
|
314
316
|
}
|
|
315
317
|
|
|
316
318
|
return annotation
|
|
@@ -421,7 +423,7 @@ export class ObservableObjectAdministration
|
|
|
421
423
|
const observable = new ObservableValue(
|
|
422
424
|
value,
|
|
423
425
|
enhancer,
|
|
424
|
-
`${this.name_}.${
|
|
426
|
+
__DEV__ ? `${this.name_}.${key.toString()}` : "ObservableObject.key",
|
|
425
427
|
false
|
|
426
428
|
)
|
|
427
429
|
|
|
@@ -461,7 +463,7 @@ export class ObservableObjectAdministration
|
|
|
461
463
|
})
|
|
462
464
|
if (!change) return null
|
|
463
465
|
}
|
|
464
|
-
options.name ||= `${this.name_}.${
|
|
466
|
+
options.name ||= __DEV__ ? `${this.name_}.${key.toString()}` : "ObservableObject.key"
|
|
465
467
|
options.context = this.proxy_ || this.target_
|
|
466
468
|
const cachedDescriptor = getCachedObservablePropDescriptor(key)
|
|
467
469
|
const descriptor = {
|
|
@@ -645,19 +647,32 @@ export function asObservableObject(
|
|
|
645
647
|
die(`Options can't be provided for already observable objects.`)
|
|
646
648
|
}
|
|
647
649
|
|
|
648
|
-
if (hasProp(target, $mobx))
|
|
650
|
+
if (hasProp(target, $mobx)) {
|
|
651
|
+
if (__DEV__ && !(getAdministration(target) instanceof ObservableObjectAdministration)) {
|
|
652
|
+
die(
|
|
653
|
+
`Cannot convert '${getDebugName(target)}' into observable object:` +
|
|
654
|
+
`\nThe target is already observable of different type.` +
|
|
655
|
+
`\nExtending builtins is not supported.`
|
|
656
|
+
)
|
|
657
|
+
}
|
|
658
|
+
return target
|
|
659
|
+
}
|
|
649
660
|
|
|
650
661
|
if (__DEV__ && !Object.isExtensible(target))
|
|
651
662
|
die("Cannot make the designated object observable; it is not extensible")
|
|
652
663
|
|
|
653
664
|
const name =
|
|
654
665
|
options?.name ??
|
|
655
|
-
|
|
666
|
+
(__DEV__
|
|
667
|
+
? `${
|
|
668
|
+
isPlainObject(target) ? "ObservableObject" : target.constructor.name
|
|
669
|
+
}@${getNextId()}`
|
|
670
|
+
: "ObservableObject")
|
|
656
671
|
|
|
657
672
|
const adm = new ObservableObjectAdministration(
|
|
658
673
|
target,
|
|
659
674
|
new Map(),
|
|
660
|
-
|
|
675
|
+
String(name),
|
|
661
676
|
getAnnotationFromOptions(options),
|
|
662
677
|
options?.autoBind
|
|
663
678
|
)
|
|
@@ -702,9 +717,7 @@ export function recordAnnotationApplied(
|
|
|
702
717
|
adm.appliedAnnotations_![key] = annotation
|
|
703
718
|
}
|
|
704
719
|
// Remove applied decorator annotation so we don't try to apply it again in subclass constructor
|
|
705
|
-
|
|
706
|
-
delete adm.target_[storedAnnotationsSymbol][key]
|
|
707
|
-
}
|
|
720
|
+
delete adm.target_[storedAnnotationsSymbol]?.[key]
|
|
708
721
|
}
|
|
709
722
|
|
|
710
723
|
function assertAnnotable(
|
|
@@ -74,7 +74,7 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
|
|
|
74
74
|
constructor(
|
|
75
75
|
initialData?: IObservableSetInitialValues<T>,
|
|
76
76
|
enhancer: IEnhancer<T> = deepEnhancer,
|
|
77
|
-
public name_ = "ObservableSet@" + getNextId()
|
|
77
|
+
public name_ = __DEV__ ? "ObservableSet@" + getNextId() : "ObservableSet"
|
|
78
78
|
) {
|
|
79
79
|
if (!isFunction(Set)) {
|
|
80
80
|
die(22)
|
|
@@ -71,7 +71,7 @@ export class ObservableValue<T>
|
|
|
71
71
|
constructor(
|
|
72
72
|
value: T,
|
|
73
73
|
public enhancer: IEnhancer<T>,
|
|
74
|
-
public name_ = "ObservableValue@" + getNextId(),
|
|
74
|
+
public name_ = __DEV__ ? "ObservableValue@" + getNextId() : "ObservableValue",
|
|
75
75
|
notifySpy = true,
|
|
76
76
|
private equals: IEqualsComparer<any> = comparer.default
|
|
77
77
|
) {
|
package/src/types/type-utils.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isAction } from "../api/action"
|
|
1
2
|
import {
|
|
2
3
|
$mobx,
|
|
3
4
|
IDepTreeNode,
|
|
@@ -12,7 +13,7 @@ import {
|
|
|
12
13
|
isFunction
|
|
13
14
|
} from "../internal"
|
|
14
15
|
|
|
15
|
-
export function getAtom(thing: any, property?:
|
|
16
|
+
export function getAtom(thing: any, property?: PropertyKey): IDepTreeNode {
|
|
16
17
|
if (typeof thing === "object" && thing !== null) {
|
|
17
18
|
if (isObservableArray(thing)) {
|
|
18
19
|
if (property !== undefined) die(23)
|
|
@@ -57,9 +58,15 @@ export function getAdministration(thing: any, property?: string) {
|
|
|
57
58
|
|
|
58
59
|
export function getDebugName(thing: any, property?: string): string {
|
|
59
60
|
let named
|
|
60
|
-
if (property !== undefined)
|
|
61
|
-
|
|
61
|
+
if (property !== undefined) {
|
|
62
|
+
named = getAtom(thing, property)
|
|
63
|
+
} else if (isAction(thing)) {
|
|
64
|
+
return thing.name
|
|
65
|
+
} else if (isObservableObject(thing) || isObservableMap(thing) || isObservableSet(thing)) {
|
|
62
66
|
named = getAdministration(thing)
|
|
63
|
-
else
|
|
67
|
+
} else {
|
|
68
|
+
// valid for arrays as well
|
|
69
|
+
named = getAtom(thing)
|
|
70
|
+
}
|
|
64
71
|
return named.name_
|
|
65
72
|
}
|