mobx 6.13.3 → 6.13.5
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/core/reaction.d.ts +1 -1
- package/dist/mobx.cjs.development.js +18 -5
- 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 +18 -5
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +18 -5
- 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 +18 -5
- 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/legacyobservablearray.d.ts +1 -1
- package/dist/types/observablemap.d.ts +4 -4
- package/dist/types/observableobject.d.ts +1 -1
- package/dist/types/observableset.d.ts +4 -4
- package/dist/utils/iterable.d.ts +1 -1
- package/package.json +1 -1
- package/src/types/observablemap.ts +11 -6
- package/src/types/observableset.ts +14 -9
- package/src/utils/iterable.ts +9 -2
|
@@ -7,7 +7,7 @@ export declare class LegacyObservableArray<T> extends StubArray {
|
|
|
7
7
|
get length(): number;
|
|
8
8
|
set length(newLength: number);
|
|
9
9
|
get [Symbol.toStringTag](): string;
|
|
10
|
-
[Symbol.iterator]():
|
|
10
|
+
[Symbol.iterator](): IteratorObject<any, unknown, unknown>;
|
|
11
11
|
}
|
|
12
12
|
export declare function reserveArrayBuffer(max: number): void;
|
|
13
13
|
export declare function createLegacyArray<T>(initialValues: T[] | undefined, enhancer: IEnhancer<T>, name?: string): IObservableArray<T>;
|
|
@@ -54,10 +54,10 @@ export declare class ObservableMap<K = any, V = any> implements Map<K, V>, IInte
|
|
|
54
54
|
private addValue_;
|
|
55
55
|
get(key: K): V | undefined;
|
|
56
56
|
private dehanceValue_;
|
|
57
|
-
keys():
|
|
58
|
-
values():
|
|
59
|
-
entries():
|
|
60
|
-
[Symbol.iterator]():
|
|
57
|
+
keys(): MapIterator<K>;
|
|
58
|
+
values(): MapIterator<V>;
|
|
59
|
+
entries(): MapIterator<IMapEntry<K, V>>;
|
|
60
|
+
[Symbol.iterator](): MapIterator<IMapEntry<K, V>>;
|
|
61
61
|
forEach(callback: (value: V, key: K, object: Map<K, V>) => void, thisArg?: any): void;
|
|
62
62
|
/** Merge another object into this object, returns this. */
|
|
63
63
|
merge(other?: IObservableMapInitialValues<K, V>): ObservableMap<K, V>;
|
|
@@ -37,7 +37,7 @@ export declare class ObservableObjectAdministration implements IInterceptable<IO
|
|
|
37
37
|
isPlainObject_: boolean;
|
|
38
38
|
appliedAnnotations_?: object;
|
|
39
39
|
private pendingKeys_;
|
|
40
|
-
constructor(target_: any, values_: Map<PropertyKey, ObservableValue<any> | ComputedValue<any
|
|
40
|
+
constructor(target_: any, values_: Map<PropertyKey, ObservableValue<any> | ComputedValue<any>> | undefined, name_: string, defaultAnnotation_?: Annotation);
|
|
41
41
|
getObservablePropValue_(key: PropertyKey): any;
|
|
42
42
|
setObservablePropValue_(key: PropertyKey, newValue: any): boolean | null;
|
|
43
43
|
get_(key: PropertyKey): any;
|
|
@@ -39,9 +39,9 @@ export declare class ObservableSet<T = any> implements Set<T>, IInterceptable<IS
|
|
|
39
39
|
add(value: T): this;
|
|
40
40
|
delete(value: T): boolean;
|
|
41
41
|
has(value: T): boolean;
|
|
42
|
-
entries():
|
|
43
|
-
keys():
|
|
44
|
-
values():
|
|
42
|
+
entries(): SetIterator<[T, T]>;
|
|
43
|
+
keys(): SetIterator<T>;
|
|
44
|
+
values(): SetIterator<T>;
|
|
45
45
|
intersection<U>(otherSet: ReadonlySetLike<U> | Set<U>): Set<T & U>;
|
|
46
46
|
union<U>(otherSet: ReadonlySetLike<U> | Set<U>): Set<T | U>;
|
|
47
47
|
difference<U>(otherSet: ReadonlySetLike<U>): Set<T>;
|
|
@@ -54,7 +54,7 @@ export declare class ObservableSet<T = any> implements Set<T>, IInterceptable<IS
|
|
|
54
54
|
intercept_(handler: IInterceptor<ISetWillChange<T>>): Lambda;
|
|
55
55
|
toJSON(): T[];
|
|
56
56
|
toString(): string;
|
|
57
|
-
[Symbol.iterator]():
|
|
57
|
+
[Symbol.iterator](): SetIterator<T>;
|
|
58
58
|
get [Symbol.toStringTag](): string;
|
|
59
59
|
}
|
|
60
60
|
export declare var isObservableSet: (thing: any) => thing is ObservableSet<any>;
|
package/dist/utils/iterable.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function makeIterable<T>(iterator: Iterator<T>):
|
|
1
|
+
export declare function makeIterable<T, TReturn = unknown>(iterator: Iterator<T>): IteratorObject<T, TReturn>;
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
checkIfStateModificationsAreAllowed,
|
|
10
10
|
createAtom,
|
|
11
11
|
createInstanceofPredicate,
|
|
12
|
+
makeIterable,
|
|
12
13
|
deepEnhancer,
|
|
13
14
|
getNextId,
|
|
14
15
|
getPlainObjectKeys,
|
|
@@ -19,7 +20,6 @@ import {
|
|
|
19
20
|
isPlainES6Map,
|
|
20
21
|
isPlainObject,
|
|
21
22
|
isSpyEnabled,
|
|
22
|
-
makeIterable,
|
|
23
23
|
notifyListeners,
|
|
24
24
|
referenceEnhancer,
|
|
25
25
|
registerInterceptor,
|
|
@@ -296,15 +296,15 @@ export class ObservableMap<K = any, V = any>
|
|
|
296
296
|
return value
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
keys():
|
|
299
|
+
keys(): MapIterator<K> {
|
|
300
300
|
this.keysAtom_.reportObserved()
|
|
301
301
|
return this.data_.keys()
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
-
values():
|
|
304
|
+
values(): MapIterator<V> {
|
|
305
305
|
const self = this
|
|
306
306
|
const keys = this.keys()
|
|
307
|
-
return
|
|
307
|
+
return makeIterableForMap({
|
|
308
308
|
next() {
|
|
309
309
|
const { done, value } = keys.next()
|
|
310
310
|
return {
|
|
@@ -315,10 +315,10 @@ export class ObservableMap<K = any, V = any>
|
|
|
315
315
|
})
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
-
entries():
|
|
318
|
+
entries(): MapIterator<IMapEntry<K, V>> {
|
|
319
319
|
const self = this
|
|
320
320
|
const keys = this.keys()
|
|
321
|
-
return
|
|
321
|
+
return makeIterableForMap({
|
|
322
322
|
next() {
|
|
323
323
|
const { done, value } = keys.next()
|
|
324
324
|
return {
|
|
@@ -490,6 +490,11 @@ export var isObservableMap = createInstanceofPredicate("ObservableMap", Observab
|
|
|
490
490
|
thing: any
|
|
491
491
|
) => thing is ObservableMap<any, any>
|
|
492
492
|
|
|
493
|
+
function makeIterableForMap<T>(iterator: Iterator<T>): MapIterator<T> {
|
|
494
|
+
iterator[Symbol.toStringTag] = "MapIterator"
|
|
495
|
+
return makeIterable<T, BuiltinIteratorReturn>(iterator)
|
|
496
|
+
}
|
|
497
|
+
|
|
493
498
|
function convertToMap(dataStructure: any): Map<any, any> {
|
|
494
499
|
if (isES6Map(dataStructure) || isObservableMap(dataStructure)) {
|
|
495
500
|
return dataStructure
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
notifyListeners,
|
|
14
14
|
spyReportEnd,
|
|
15
15
|
createInstanceofPredicate,
|
|
16
|
+
makeIterable,
|
|
16
17
|
hasInterceptors,
|
|
17
18
|
interceptChange,
|
|
18
19
|
IInterceptable,
|
|
@@ -20,7 +21,6 @@ import {
|
|
|
20
21
|
registerInterceptor,
|
|
21
22
|
checkIfStateModificationsAreAllowed,
|
|
22
23
|
untracked,
|
|
23
|
-
makeIterable,
|
|
24
24
|
transaction,
|
|
25
25
|
isES6Set,
|
|
26
26
|
IAtom,
|
|
@@ -214,33 +214,33 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
|
|
|
214
214
|
let nextIndex = 0
|
|
215
215
|
const keys = Array.from(this.keys())
|
|
216
216
|
const values = Array.from(this.values())
|
|
217
|
-
return
|
|
217
|
+
return makeIterableForSet<[T, T]>({
|
|
218
218
|
next() {
|
|
219
219
|
const index = nextIndex
|
|
220
220
|
nextIndex += 1
|
|
221
221
|
return index < values.length
|
|
222
222
|
? { value: [keys[index], values[index]], done: false }
|
|
223
|
-
: { done: true }
|
|
223
|
+
: { value: undefined, done: true }
|
|
224
224
|
}
|
|
225
|
-
}
|
|
225
|
+
})
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
keys():
|
|
228
|
+
keys(): SetIterator<T> {
|
|
229
229
|
return this.values()
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
values():
|
|
232
|
+
values(): SetIterator<T> {
|
|
233
233
|
this.atom_.reportObserved()
|
|
234
234
|
const self = this
|
|
235
235
|
let nextIndex = 0
|
|
236
236
|
const observableValues = Array.from(this.data_.values())
|
|
237
|
-
return
|
|
237
|
+
return makeIterableForSet({
|
|
238
238
|
next() {
|
|
239
239
|
return nextIndex < observableValues.length
|
|
240
240
|
? { value: self.dehanceValue_(observableValues[nextIndex++]), done: false }
|
|
241
|
-
: { done: true }
|
|
241
|
+
: { value: undefined, done: true }
|
|
242
242
|
}
|
|
243
|
-
}
|
|
243
|
+
})
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
intersection<U>(otherSet: ReadonlySetLike<U> | Set<U>): Set<T & U> {
|
|
@@ -343,3 +343,8 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
|
|
|
343
343
|
export var isObservableSet = createInstanceofPredicate("ObservableSet", ObservableSet) as (
|
|
344
344
|
thing: any
|
|
345
345
|
) => thing is ObservableSet<any>
|
|
346
|
+
|
|
347
|
+
function makeIterableForSet<T>(iterator: Iterator<T>): SetIterator<T> {
|
|
348
|
+
iterator[Symbol.toStringTag] = "SetIterator"
|
|
349
|
+
return makeIterable<T, BuiltinIteratorReturn>(iterator)
|
|
350
|
+
}
|
package/src/utils/iterable.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { getGlobal } from "../internal"
|
|
2
|
+
|
|
3
|
+
// safely get iterator prototype if available
|
|
4
|
+
const maybeIteratorPrototype = getGlobal().Iterator?.prototype || {}
|
|
5
|
+
|
|
6
|
+
export function makeIterable<T, TReturn = unknown>(
|
|
7
|
+
iterator: Iterator<T>
|
|
8
|
+
): IteratorObject<T, TReturn> {
|
|
2
9
|
iterator[Symbol.iterator] = getSelf
|
|
3
|
-
return iterator
|
|
10
|
+
return Object.assign(Object.create(maybeIteratorPrototype), iterator)
|
|
4
11
|
}
|
|
5
12
|
|
|
6
13
|
function getSelf() {
|