mobx 6.13.2 → 6.13.4

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.
@@ -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](): IterableIterator<any>;
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(): IterableIterator<K>;
58
- values(): IterableIterator<V>;
59
- entries(): IterableIterator<IMapEntry<K, V>>;
60
- [Symbol.iterator](): IterableIterator<IMapEntry<K, V>>;
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>>, name_: string, defaultAnnotation_?: Annotation);
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(): IterableIterator<[T, T]>;
43
- keys(): IterableIterator<T>;
44
- values(): IterableIterator<T>;
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](): IterableIterator<T>;
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>;
@@ -1 +1 @@
1
- export declare function makeIterable<T>(iterator: Iterator<T>): IterableIterator<T>;
1
+ export declare function makeIterable<T, TReturn = unknown>(iterator: Iterator<T>): IteratorObject<T, TReturn>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx",
3
- "version": "6.13.2",
3
+ "version": "6.13.4",
4
4
  "description": "Simple, scalable state management.",
5
5
  "source": "src/mobx.ts",
6
6
  "main": "dist/index.js",
@@ -8,8 +8,7 @@ import {
8
8
  Annotation,
9
9
  globalState,
10
10
  MakeResult,
11
- assert20223DecoratorType,
12
- storeAnnotation
11
+ assert20223DecoratorType
13
12
  } from "../internal"
14
13
 
15
14
  export function createActionAnnotation(name: string, options?: object): Annotation {
@@ -73,12 +72,18 @@ function decorate_20223_(this: Annotation, mthd, context: DecoratorContext) {
73
72
  const _createAction = m =>
74
73
  createAction(ann.options_?.name ?? name!.toString(), m, ann.options_?.autoAction ?? false)
75
74
 
76
- // Backwards/Legacy behavior, expects makeObservable(this)
77
75
  if (kind == "field") {
78
- addInitializer(function () {
79
- storeAnnotation(this, name, ann)
80
- })
81
- return
76
+ return function (initMthd) {
77
+ let mthd = initMthd
78
+ if (!isAction(mthd)) {
79
+ mthd = _createAction(mthd)
80
+ }
81
+ if (ann.options_?.bound) {
82
+ mthd = mthd.bind(this)
83
+ mthd.isMobxAction = true
84
+ }
85
+ return mthd
86
+ }
82
87
  }
83
88
 
84
89
  if (kind == "method") {
@@ -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(): IterableIterator<K> {
299
+ keys(): MapIterator<K> {
300
300
  this.keysAtom_.reportObserved()
301
301
  return this.data_.keys()
302
302
  }
303
303
 
304
- values(): IterableIterator<V> {
304
+ values(): MapIterator<V> {
305
305
  const self = this
306
306
  const keys = this.keys()
307
- return makeIterable({
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(): IterableIterator<IMapEntry<K, V>> {
318
+ entries(): MapIterator<IMapEntry<K, V>> {
319
319
  const self = this
320
320
  const keys = this.keys()
321
- return makeIterable({
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 makeIterable<[T, T]>({
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
- } as any)
225
+ })
226
226
  }
227
227
 
228
- keys(): IterableIterator<T> {
228
+ keys(): SetIterator<T> {
229
229
  return this.values()
230
230
  }
231
231
 
232
- values(): IterableIterator<T> {
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 makeIterable<T>({
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
- } as any)
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
+ }
@@ -1,8 +1,5 @@
1
- export function makeIterable<T>(iterator: Iterator<T>): IterableIterator<T> {
2
- iterator[Symbol.iterator] = getSelf
3
- return iterator as any
4
- }
5
-
6
- function getSelf() {
7
- return this
1
+ export function makeIterable<T, TReturn = unknown>(
2
+ iterator: Iterator<T>
3
+ ): IteratorObject<T, TReturn> {
4
+ return Object.assign(Object.create(Iterator.prototype), iterator)
8
5
  }