mobx 6.13.5 → 6.13.7
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 +12 -0
- package/dist/mobx.cjs.development.js +24 -22
- 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 +24 -22
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +24 -22
- 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 +24 -22
- 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/observableset.d.ts +4 -2
- package/package.json +1 -1
- package/src/types/observableset.ts +27 -27
- package/src/utils/eq.ts +5 -4
|
@@ -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
|
@@ -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
|
|
@@ -211,16 +216,11 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
|
|
|
211
216
|
}
|
|
212
217
|
|
|
213
218
|
entries() {
|
|
214
|
-
|
|
215
|
-
const keys = Array.from(this.keys())
|
|
216
|
-
const values = Array.from(this.values())
|
|
219
|
+
const values = this.values()
|
|
217
220
|
return makeIterableForSet<[T, T]>({
|
|
218
221
|
next() {
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
return index < values.length
|
|
222
|
-
? { value: [keys[index], values[index]], done: false }
|
|
223
|
-
: { value: undefined, done: true }
|
|
222
|
+
const { value, done } = values.next()
|
|
223
|
+
return !done ? { value: [value, value], done } : { value: undefined, done }
|
|
224
224
|
}
|
|
225
225
|
})
|
|
226
226
|
}
|
|
@@ -232,13 +232,13 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
|
|
|
232
232
|
values(): SetIterator<T> {
|
|
233
233
|
this.atom_.reportObserved()
|
|
234
234
|
const self = this
|
|
235
|
-
|
|
236
|
-
const observableValues = Array.from(this.data_.values())
|
|
235
|
+
const values = this.data_.values()
|
|
237
236
|
return makeIterableForSet({
|
|
238
237
|
next() {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
238
|
+
const { value, done } = values.next()
|
|
239
|
+
return !done
|
|
240
|
+
? { value: self.dehanceValue_(value), done }
|
|
241
|
+
: { value: undefined, done }
|
|
242
242
|
}
|
|
243
243
|
})
|
|
244
244
|
}
|
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
|
}
|