mobx 6.13.6 → 6.15.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 +22 -0
- package/README.md +1 -0
- package/dist/api/observable.d.ts +10 -2
- package/dist/mobx.cjs.development.js +15 -9
- 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 +15 -9
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +15 -9
- 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 +15 -9
- 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 +1 -1
- package/dist/types/observableset.d.ts +4 -2
- package/package.json +1 -1
- package/src/api/observable.ts +22 -4
- package/src/core/reaction.ts +4 -0
- package/src/types/autoannotation.ts +5 -2
- package/src/types/observablemap.ts +1 -1
- package/src/types/observableset.ts +19 -14
- package/src/types/observablevalue.ts +1 -1
- package/src/utils/eq.ts +5 -4
|
@@ -5,7 +5,7 @@ export interface IKeyValueMap<V = any> {
|
|
|
5
5
|
export type IMapEntry<K = any, V = any> = [K, V];
|
|
6
6
|
export type IReadonlyMapEntry<K = any, V = any> = readonly [K, V];
|
|
7
7
|
export type IMapEntries<K = any, V = any> = IMapEntry<K, V>[];
|
|
8
|
-
export type IReadonlyMapEntries<K = any, V = any> = IReadonlyMapEntry<K, V>[];
|
|
8
|
+
export type IReadonlyMapEntries<K = any, V = any> = readonly IReadonlyMapEntry<K, V>[];
|
|
9
9
|
export type IMapDidChange<K = any, V = any> = {
|
|
10
10
|
observableKind: "map";
|
|
11
11
|
debugObjectName: string;
|
|
@@ -13,15 +13,17 @@ export type ISetDidChange<T = any> = {
|
|
|
13
13
|
type: "delete";
|
|
14
14
|
oldValue: T;
|
|
15
15
|
};
|
|
16
|
-
export type
|
|
16
|
+
export type ISetWillDeleteChange<T = any> = {
|
|
17
17
|
type: "delete";
|
|
18
18
|
object: ObservableSet<T>;
|
|
19
19
|
oldValue: T;
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
|
+
export type ISetWillAddChange<T = any> = {
|
|
21
22
|
type: "add";
|
|
22
23
|
object: ObservableSet<T>;
|
|
23
24
|
newValue: T;
|
|
24
25
|
};
|
|
26
|
+
export type ISetWillChange<T = any> = ISetWillDeleteChange<T> | ISetWillAddChange<T>;
|
|
25
27
|
export declare class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillChange>, IListenable {
|
|
26
28
|
name_: string;
|
|
27
29
|
[$mobx]: {};
|
package/package.json
CHANGED
package/src/api/observable.ts
CHANGED
|
@@ -3,6 +3,9 @@ import {
|
|
|
3
3
|
IEqualsComparer,
|
|
4
4
|
IObservableArray,
|
|
5
5
|
IObservableMapInitialValues,
|
|
6
|
+
IMapEntries,
|
|
7
|
+
IReadonlyMapEntries,
|
|
8
|
+
IKeyValueMap,
|
|
6
9
|
IObservableSetInitialValues,
|
|
7
10
|
IObservableValue,
|
|
8
11
|
ObservableMap,
|
|
@@ -151,6 +154,24 @@ export interface IObservableValueFactory {
|
|
|
151
154
|
<T>(value?: T, options?: CreateObservableOptions): IObservableValue<T | undefined>
|
|
152
155
|
}
|
|
153
156
|
|
|
157
|
+
export interface IObservableMapFactory {
|
|
158
|
+
<K = any, V = any>(): ObservableMap<K, V>
|
|
159
|
+
<K, V>(initialValues?: IMapEntries<K, V>, options?: CreateObservableOptions): ObservableMap<
|
|
160
|
+
K,
|
|
161
|
+
V
|
|
162
|
+
>
|
|
163
|
+
<K, V>(
|
|
164
|
+
initialValues?: IReadonlyMapEntries<K, V>,
|
|
165
|
+
options?: CreateObservableOptions
|
|
166
|
+
): ObservableMap<K, V>
|
|
167
|
+
<K, V>(initialValues?: IKeyValueMap<V>, options?: CreateObservableOptions): ObservableMap<K, V>
|
|
168
|
+
<K, V>(initialValues?: Map<K, V>, options?: CreateObservableOptions): ObservableMap<K, V>
|
|
169
|
+
<K = any, V = any>(initialValues: undefined, options?: CreateObservableOptions): ObservableMap<
|
|
170
|
+
K,
|
|
171
|
+
V
|
|
172
|
+
>
|
|
173
|
+
}
|
|
174
|
+
|
|
154
175
|
export interface IObservableFactory
|
|
155
176
|
extends Annotation,
|
|
156
177
|
PropertyDecorator,
|
|
@@ -172,10 +193,7 @@ export interface IObservableFactory
|
|
|
172
193
|
initialValues?: IObservableSetInitialValues<T>,
|
|
173
194
|
options?: CreateObservableOptions
|
|
174
195
|
) => ObservableSet<T>
|
|
175
|
-
map:
|
|
176
|
-
initialValues?: IObservableMapInitialValues<K, V>,
|
|
177
|
-
options?: CreateObservableOptions
|
|
178
|
-
) => ObservableMap<K, V>
|
|
196
|
+
map: IObservableMapFactory
|
|
179
197
|
object: <T = any>(
|
|
180
198
|
props: T,
|
|
181
199
|
decorators?: AnnotationsMap<T, never>,
|
package/src/core/reaction.ts
CHANGED
|
@@ -240,6 +240,10 @@ export class Reaction implements IDerivation, IReactionPublic {
|
|
|
240
240
|
abortSignal?.addEventListener?.("abort", dispose)
|
|
241
241
|
dispose[$mobx] = this
|
|
242
242
|
|
|
243
|
+
if ("dispose" in Symbol && typeof Symbol.dispose === "symbol") {
|
|
244
|
+
dispose[Symbol.dispose] = dispose
|
|
245
|
+
}
|
|
246
|
+
|
|
243
247
|
return dispose
|
|
244
248
|
}
|
|
245
249
|
|
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
autoAction,
|
|
11
11
|
isGenerator,
|
|
12
12
|
MakeResult,
|
|
13
|
-
die
|
|
13
|
+
die,
|
|
14
|
+
isAction
|
|
14
15
|
} from "../internal"
|
|
15
16
|
|
|
16
17
|
const AUTO = "true"
|
|
@@ -40,7 +41,9 @@ function make_(
|
|
|
40
41
|
// lone setter -> action setter
|
|
41
42
|
if (descriptor.set) {
|
|
42
43
|
// TODO make action applicable to setter and delegate to action.make_
|
|
43
|
-
const set =
|
|
44
|
+
const set = isAction(descriptor.set)
|
|
45
|
+
? descriptor.set // See #4553
|
|
46
|
+
: (createAction(key.toString(), descriptor.set) as (v: any) => void)
|
|
44
47
|
// own
|
|
45
48
|
if (source === adm.target_) {
|
|
46
49
|
return adm.defineProperty_(key, {
|
|
@@ -46,7 +46,7 @@ export interface IKeyValueMap<V = any> {
|
|
|
46
46
|
export type IMapEntry<K = any, V = any> = [K, V]
|
|
47
47
|
export type IReadonlyMapEntry<K = any, V = any> = readonly [K, V]
|
|
48
48
|
export type IMapEntries<K = any, V = any> = IMapEntry<K, V>[]
|
|
49
|
-
export type IReadonlyMapEntries<K = any, V = any> = IReadonlyMapEntry<K, V>[]
|
|
49
|
+
export type IReadonlyMapEntries<K = any, V = any> = readonly IReadonlyMapEntry<K, V>[]
|
|
50
50
|
|
|
51
51
|
export type IMapDidChange<K = any, V = any> = { observableKind: "map"; debugObjectName: string } & (
|
|
52
52
|
| {
|
|
@@ -51,17 +51,20 @@ export type ISetDidChange<T = any> =
|
|
|
51
51
|
oldValue: T
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
export type ISetWillDeleteChange<T = any> = {
|
|
55
|
+
type: "delete"
|
|
56
|
+
object: ObservableSet<T>
|
|
57
|
+
oldValue: T
|
|
58
|
+
};
|
|
59
|
+
export type ISetWillAddChange<T = any> = {
|
|
60
|
+
type: "add"
|
|
61
|
+
object: ObservableSet<T>
|
|
62
|
+
newValue: T
|
|
63
|
+
};
|
|
64
|
+
|
|
54
65
|
export type ISetWillChange<T = any> =
|
|
55
|
-
|
|
|
56
|
-
|
|
57
|
-
object: ObservableSet<T>
|
|
58
|
-
oldValue: T
|
|
59
|
-
}
|
|
60
|
-
| {
|
|
61
|
-
type: "add"
|
|
62
|
-
object: ObservableSet<T>
|
|
63
|
-
newValue: T
|
|
64
|
-
}
|
|
66
|
+
| ISetWillDeleteChange<T>
|
|
67
|
+
| ISetWillAddChange<T>
|
|
65
68
|
|
|
66
69
|
export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillChange>, IListenable {
|
|
67
70
|
[$mobx] = ObservableSetMarker
|
|
@@ -120,7 +123,7 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
|
|
|
120
123
|
add(value: T) {
|
|
121
124
|
checkIfStateModificationsAreAllowed(this.atom_)
|
|
122
125
|
if (hasInterceptors(this)) {
|
|
123
|
-
const change = interceptChange<
|
|
126
|
+
const change = interceptChange<ISetWillAddChange<T>>(this, {
|
|
124
127
|
type: ADD,
|
|
125
128
|
object: this,
|
|
126
129
|
newValue: value
|
|
@@ -128,8 +131,10 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
|
|
|
128
131
|
if (!change) {
|
|
129
132
|
return this
|
|
130
133
|
}
|
|
131
|
-
|
|
132
|
-
//
|
|
134
|
+
|
|
135
|
+
// implemented reassignment same as it's done for ObservableMap
|
|
136
|
+
value = change.newValue!;
|
|
137
|
+
|
|
133
138
|
}
|
|
134
139
|
if (!this.has(value)) {
|
|
135
140
|
transaction(() => {
|
|
@@ -164,7 +169,7 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
|
|
|
164
169
|
|
|
165
170
|
delete(value: T) {
|
|
166
171
|
if (hasInterceptors(this)) {
|
|
167
|
-
const change = interceptChange<
|
|
172
|
+
const change = interceptChange<ISetWillDeleteChange<T>>(this, {
|
|
168
173
|
type: DELETE,
|
|
169
174
|
object: this,
|
|
170
175
|
oldValue: value
|
package/src/utils/eq.ts
CHANGED
|
@@ -17,6 +17,8 @@ export function deepEqual(a: any, b: any, depth: number = -1): boolean {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// Copied from https://github.com/jashkenas/underscore/blob/5c237a7c682fb68fd5378203f0bf22dce1624854/underscore.js#L1186-L1289
|
|
20
|
+
// Modified: "Deep compare objects" part to iterate over keys in forward order instead of reverse order.
|
|
21
|
+
//
|
|
20
22
|
// Internal recursive comparison function for `isEqual`.
|
|
21
23
|
function eq(a: any, b: any, depth: number, aStack?: any[], bStack?: any[]) {
|
|
22
24
|
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
|
@@ -149,15 +151,14 @@ function eq(a: any, b: any, depth: number, aStack?: any[], bStack?: any[]) {
|
|
|
149
151
|
} else {
|
|
150
152
|
// Deep compare objects.
|
|
151
153
|
const keys = Object.keys(a)
|
|
152
|
-
|
|
153
|
-
length = keys.length
|
|
154
|
+
const length = keys.length
|
|
154
155
|
// Ensure that both objects contain the same number of properties before comparing deep equality.
|
|
155
156
|
if (Object.keys(b).length !== length) {
|
|
156
157
|
return false
|
|
157
158
|
}
|
|
158
|
-
|
|
159
|
+
for (let i = 0; i < length; i++) {
|
|
159
160
|
// Deep compare each member
|
|
160
|
-
key = keys[
|
|
161
|
+
const key = keys[i]
|
|
161
162
|
if (!(hasProp(b, key) && eq(a[key], b[key], depth - 1, aStack, bStack))) {
|
|
162
163
|
return false
|
|
163
164
|
}
|