mobx 6.5.0 → 6.6.2
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 -2
- package/README.md +39 -43
- package/dist/api/observable.d.ts +5 -1
- package/dist/mobx.cjs.development.js +25 -17
- 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 +25 -17
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +25 -17
- 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 +25 -17
- 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/observablemap.d.ts +3 -1
- package/package.json +1 -1
- package/src/api/decorators.ts +1 -1
- package/src/api/observable.ts +8 -3
- package/src/mobx.ts +1 -1
- package/src/types/legacyobservablearray.ts +21 -0
- package/src/types/observablemap.ts +4 -2
- package/src/types/observableobject.ts +1 -1
|
@@ -3,7 +3,9 @@ export interface IKeyValueMap<V = any> {
|
|
|
3
3
|
[key: string]: V;
|
|
4
4
|
}
|
|
5
5
|
export declare type IMapEntry<K = any, V = any> = [K, V];
|
|
6
|
+
export declare type IReadonlyMapEntry<K = any, V = any> = readonly [K, V];
|
|
6
7
|
export declare type IMapEntries<K = any, V = any> = IMapEntry<K, V>[];
|
|
8
|
+
export declare type IReadonlyMapEntries<K = any, V = any> = IReadonlyMapEntry<K, V>[];
|
|
7
9
|
export declare type IMapDidChange<K = any, V = any> = {
|
|
8
10
|
observableKind: "map";
|
|
9
11
|
debugObjectName: string;
|
|
@@ -32,7 +34,7 @@ export interface IMapWillChange<K = any, V = any> {
|
|
|
32
34
|
}
|
|
33
35
|
export declare const ADD = "add";
|
|
34
36
|
export declare const DELETE = "delete";
|
|
35
|
-
export declare type IObservableMapInitialValues<K = any, V = any> = IMapEntries<K, V> | IKeyValueMap<V> | Map<K, V>;
|
|
37
|
+
export declare type IObservableMapInitialValues<K = any, V = any> = IMapEntries<K, V> | IReadonlyMapEntries<K, V> | IKeyValueMap<V> | Map<K, V>;
|
|
36
38
|
export declare class ObservableMap<K = any, V = any> implements Map<K, V>, IInterceptable<IMapWillChange<K, V>>, IListenable {
|
|
37
39
|
enhancer_: IEnhancer<V>;
|
|
38
40
|
name_: string;
|
package/package.json
CHANGED
package/src/api/decorators.ts
CHANGED
|
@@ -51,7 +51,7 @@ function assertNotDecorated(prototype: object, annotation: Annotation, key: Prop
|
|
|
51
51
|
`Cannot apply '@${requestedAnnotationType}' to '${fieldName}':` +
|
|
52
52
|
`\nThe field is already decorated with '@${currentAnnotationType}'.` +
|
|
53
53
|
`\nRe-decorating fields is not allowed.` +
|
|
54
|
-
`\nUse '@override' decorator for methods
|
|
54
|
+
`\nUse '@override' decorator for methods overridden by subclass.`
|
|
55
55
|
)
|
|
56
56
|
}
|
|
57
57
|
}
|
package/src/api/observable.ts
CHANGED
|
@@ -136,6 +136,11 @@ function createObservable(v: any, arg2?: any, arg3?: any) {
|
|
|
136
136
|
}
|
|
137
137
|
Object.assign(createObservable, observableDecoratorAnnotation)
|
|
138
138
|
|
|
139
|
+
export interface IObservableValueFactory {
|
|
140
|
+
<T>(value: T, options?: CreateObservableOptions): IObservableValue<T>
|
|
141
|
+
<T>(value?: T, options?: CreateObservableOptions): IObservableValue<T | undefined>
|
|
142
|
+
}
|
|
143
|
+
|
|
139
144
|
export interface IObservableFactory extends Annotation, PropertyDecorator {
|
|
140
145
|
<T = any>(value: T[], options?: CreateObservableOptions): IObservableArray<T>
|
|
141
146
|
<T = any>(value: Set<T>, options?: CreateObservableOptions): ObservableSet<T>
|
|
@@ -146,7 +151,7 @@ export interface IObservableFactory extends Annotation, PropertyDecorator {
|
|
|
146
151
|
options?: CreateObservableOptions
|
|
147
152
|
): T
|
|
148
153
|
|
|
149
|
-
box:
|
|
154
|
+
box: IObservableValueFactory
|
|
150
155
|
array: <T = any>(initialValues?: T[], options?: CreateObservableOptions) => IObservableArray<T>
|
|
151
156
|
set: <T = any>(
|
|
152
157
|
initialValues?: IObservableSetInitialValues<T>,
|
|
@@ -175,7 +180,7 @@ export interface IObservableFactory extends Annotation, PropertyDecorator {
|
|
|
175
180
|
}
|
|
176
181
|
|
|
177
182
|
const observableFactories: IObservableFactory = {
|
|
178
|
-
box<T = any>(value
|
|
183
|
+
box<T = any>(value: T, options?: CreateObservableOptions): IObservableValue<T> {
|
|
179
184
|
const o = asCreateObservableOptions(options)
|
|
180
185
|
return new ObservableValue(value, getEnhancerFromOptions(o), o.name, true, o.equals)
|
|
181
186
|
},
|
|
@@ -201,7 +206,7 @@ const observableFactories: IObservableFactory = {
|
|
|
201
206
|
const o = asCreateObservableOptions(options)
|
|
202
207
|
return new ObservableSet<T>(initialValues, getEnhancerFromOptions(o), o.name)
|
|
203
208
|
},
|
|
204
|
-
object<T = any>(
|
|
209
|
+
object<T extends object = any>(
|
|
205
210
|
props: T,
|
|
206
211
|
decorators?: AnnotationsMap<T, never>,
|
|
207
212
|
options?: CreateObservableOptions
|
package/src/mobx.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* (c) Michel Weststrate 2015 - 2020
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*
|
|
5
|
-
* Welcome to the mobx sources! To get
|
|
5
|
+
* Welcome to the mobx sources! To get a global overview of how MobX internally works,
|
|
6
6
|
* this is a good place to start:
|
|
7
7
|
* https://medium.com/@mweststrate/becoming-fully-reactive-an-in-depth-explanation-of-mobservable-55995262a254#.xvbh6qd74
|
|
8
8
|
*
|
|
@@ -14,6 +14,21 @@ import {
|
|
|
14
14
|
defineProperty
|
|
15
15
|
} from "../internal"
|
|
16
16
|
|
|
17
|
+
// Bug in safari 9.* (or iOS 9 safari mobile). See #364
|
|
18
|
+
const ENTRY_0 = createArrayEntryDescriptor(0)
|
|
19
|
+
|
|
20
|
+
const safariPrototypeSetterInheritanceBug = (() => {
|
|
21
|
+
let v = false
|
|
22
|
+
const p = {}
|
|
23
|
+
Object.defineProperty(p, "0", {
|
|
24
|
+
set: () => {
|
|
25
|
+
v = true
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
Object.create(p)["0"] = 1
|
|
29
|
+
return v === false
|
|
30
|
+
})()
|
|
31
|
+
|
|
17
32
|
/**
|
|
18
33
|
* This array buffer contains two lists of properties, so that all arrays
|
|
19
34
|
* can recycle their property definitions, which significantly improves performance of creating
|
|
@@ -57,6 +72,12 @@ class LegacyObservableArray<T> extends StubArray {
|
|
|
57
72
|
this.spliceWithArray(0, 0, initialValues)
|
|
58
73
|
allowStateChangesEnd(prev)
|
|
59
74
|
}
|
|
75
|
+
|
|
76
|
+
if (safariPrototypeSetterInheritanceBug) {
|
|
77
|
+
// Seems that Safari won't use numeric prototype setter untill any * numeric property is
|
|
78
|
+
// defined on the instance. After that it works fine, even if this property is deleted.
|
|
79
|
+
Object.defineProperty(this, "0", ENTRY_0)
|
|
80
|
+
}
|
|
60
81
|
}
|
|
61
82
|
|
|
62
83
|
concat(...arrays: T[][]): T[] {
|
|
@@ -43,7 +43,9 @@ export interface IKeyValueMap<V = any> {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export type IMapEntry<K = any, V = any> = [K, V]
|
|
46
|
+
export type IReadonlyMapEntry<K = any, V = any> = readonly [K, V]
|
|
46
47
|
export type IMapEntries<K = any, V = any> = IMapEntry<K, V>[]
|
|
48
|
+
export type IReadonlyMapEntries<K = any, V = any> = IReadonlyMapEntry<K, V>[]
|
|
47
49
|
|
|
48
50
|
export type IMapDidChange<K = any, V = any> = { observableKind: "map"; debugObjectName: string } & (
|
|
49
51
|
| {
|
|
@@ -81,14 +83,14 @@ export const DELETE = "delete"
|
|
|
81
83
|
|
|
82
84
|
export type IObservableMapInitialValues<K = any, V = any> =
|
|
83
85
|
| IMapEntries<K, V>
|
|
86
|
+
| IReadonlyMapEntries<K, V>
|
|
84
87
|
| IKeyValueMap<V>
|
|
85
88
|
| Map<K, V>
|
|
86
89
|
|
|
87
90
|
// just extend Map? See also https://gist.github.com/nestharus/13b4d74f2ef4a2f4357dbd3fc23c1e54
|
|
88
91
|
// But: https://github.com/mobxjs/mobx/issues/1556
|
|
89
92
|
export class ObservableMap<K = any, V = any>
|
|
90
|
-
implements Map<K, V>, IInterceptable<IMapWillChange<K, V>>, IListenable
|
|
91
|
-
{
|
|
93
|
+
implements Map<K, V>, IInterceptable<IMapWillChange<K, V>>, IListenable {
|
|
92
94
|
[$mobx] = ObservableMapMarker
|
|
93
95
|
data_: Map<K, ObservableValue<V>>
|
|
94
96
|
hasMap_: Map<K, ObservableValue<boolean>> // hasMap, not hashMap >-).
|
|
@@ -776,7 +776,7 @@ function assertAnnotable(
|
|
|
776
776
|
`Cannot apply '${requestedAnnotationType}' to '${fieldName}':` +
|
|
777
777
|
`\nThe field is already annotated with '${currentAnnotationType}'.` +
|
|
778
778
|
`\nRe-annotating fields is not allowed.` +
|
|
779
|
-
`\nUse 'override' annotation for methods
|
|
779
|
+
`\nUse 'override' annotation for methods overridden by subclass.`
|
|
780
780
|
)
|
|
781
781
|
}
|
|
782
782
|
}
|