mobx 6.3.13 → 6.4.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +1 -0
  3. package/dist/errors.d.ts +2 -2
  4. package/dist/mobx.cjs.development.js +940 -263
  5. package/dist/mobx.cjs.development.js.map +1 -1
  6. package/dist/mobx.cjs.production.min.js.map +1 -1
  7. package/dist/mobx.esm.development.js +940 -263
  8. package/dist/mobx.esm.development.js.map +1 -1
  9. package/dist/mobx.esm.js +958 -269
  10. package/dist/mobx.esm.js.map +1 -1
  11. package/dist/mobx.esm.production.min.js.map +1 -1
  12. package/dist/mobx.umd.development.js +940 -263
  13. package/dist/mobx.umd.development.js.map +1 -1
  14. package/dist/mobx.umd.production.min.js.map +1 -1
  15. package/dist/types/observablemap.d.ts +2 -2
  16. package/dist/utils/utils.d.ts +1 -1
  17. package/package.json +1 -1
  18. package/src/api/action.ts +8 -3
  19. package/src/api/annotation.ts +1 -2
  20. package/src/api/autorun.ts +22 -8
  21. package/src/api/computed.ts +5 -2
  22. package/src/api/configure.ts +6 -2
  23. package/src/api/extendobservable.ts +11 -5
  24. package/src/api/extras.ts +4 -2
  25. package/src/api/flow.ts +11 -4
  26. package/src/api/intercept-read.ts +4 -2
  27. package/src/api/intercept.ts +5 -2
  28. package/src/api/iscomputed.ts +10 -4
  29. package/src/api/isobservable.ts +10 -4
  30. package/src/api/makeObservable.ts +4 -2
  31. package/src/api/object-api.ts +30 -16
  32. package/src/api/observable.ts +23 -9
  33. package/src/api/observe.ts +4 -2
  34. package/src/api/tojs.ts +7 -3
  35. package/src/api/trace.ts +6 -2
  36. package/src/api/when.ts +12 -5
  37. package/src/core/action.ts +8 -3
  38. package/src/core/computedvalue.ts +29 -9
  39. package/src/core/derivation.ts +25 -9
  40. package/src/core/globalstate.ts +18 -7
  41. package/src/core/observable.ts +14 -5
  42. package/src/core/reaction.ts +15 -6
  43. package/src/core/spy.ts +20 -7
  44. package/src/errors.ts +2 -2
  45. package/src/types/actionannotation.ts +2 -2
  46. package/src/types/dynamicobject.ts +10 -4
  47. package/src/types/flowannotation.ts +3 -1
  48. package/src/types/intercept-utils.ts +9 -3
  49. package/src/types/legacyobservablearray.ts +5 -3
  50. package/src/types/listen-utils.ts +6 -2
  51. package/src/types/modifiers.ts +39 -14
  52. package/src/types/observablearray.ts +78 -30
  53. package/src/types/observablemap.ts +60 -24
  54. package/src/types/observableobject.ts +52 -18
  55. package/src/types/observableset.ts +29 -10
  56. package/src/types/observablevalue.ts +13 -5
  57. package/src/types/type-utils.ts +33 -11
  58. package/src/utils/comparer.ts +4 -4
  59. package/src/utils/eq.ts +45 -15
  60. package/src/utils/utils.ts +42 -20
@@ -58,9 +58,9 @@ export declare class ObservableMap<K = any, V = any> implements Map<K, V>, IInte
58
58
  [Symbol.iterator](): IterableIterator<IMapEntry<K, V>>;
59
59
  forEach(callback: (value: V, key: K, object: Map<K, V>) => void, thisArg?: any): void;
60
60
  /** Merge another object into this object, returns this. */
61
- merge(other: ObservableMap<K, V> | IKeyValueMap<V> | any): ObservableMap<K, V>;
61
+ merge(other?: IObservableMapInitialValues<K, V>): ObservableMap<K, V>;
62
62
  clear(): void;
63
- replace(values: ObservableMap<K, V> | IKeyValueMap<V> | any): ObservableMap<K, V>;
63
+ replace(values: IObservableMapInitialValues<K, V>): ObservableMap<K, V>;
64
64
  get size(): number;
65
65
  toString(): string;
66
66
  toJSON(): [K, V][];
@@ -30,7 +30,7 @@ export declare function isGenerator(obj: any): boolean;
30
30
  export declare function addHiddenProp(object: any, propName: PropertyKey, value: any): void;
31
31
  export declare function addHiddenFinalProp(object: any, propName: PropertyKey, value: any): void;
32
32
  export declare function createInstanceofPredicate<T>(name: string, theClass: new (...args: any[]) => T): (x: any) => x is T;
33
- export declare function isES6Map(thing: any): boolean;
33
+ export declare function isES6Map(thing: any): thing is Map<any, any>;
34
34
  export declare function isES6Set(thing: any): thing is Set<any>;
35
35
  /**
36
36
  * Returns the following: own enumerable keys and symbols.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx",
3
- "version": "6.3.13",
3
+ "version": "6.4.0",
4
4
  "description": "Simple, scalable state management.",
5
5
  "source": "src/mobx.ts",
6
6
  "main": "dist/index.js",
package/src/api/action.ts CHANGED
@@ -45,10 +45,13 @@ export interface IActionFactory extends Annotation, PropertyDecorator {
45
45
  function createActionFactory(autoAction: boolean): IActionFactory {
46
46
  const res: IActionFactory = function action(arg1, arg2?): any {
47
47
  // action(fn() {})
48
- if (isFunction(arg1))
48
+ if (isFunction(arg1)) {
49
49
  return createAction(arg1.name || DEFAULT_ACTION_NAME, arg1, autoAction)
50
+ }
50
51
  // action("name", fn() {})
51
- if (isFunction(arg2)) return createAction(arg1, arg2, autoAction)
52
+ if (isFunction(arg2)) {
53
+ return createAction(arg1, arg2, autoAction)
54
+ }
52
55
  // @action
53
56
  if (isStringish(arg2)) {
54
57
  return storeAnnotation(arg1, arg2, autoAction ? autoActionAnnotation : actionAnnotation)
@@ -63,7 +66,9 @@ function createActionFactory(autoAction: boolean): IActionFactory {
63
66
  )
64
67
  }
65
68
 
66
- if (__DEV__) die("Invalid arguments for `action`")
69
+ if (__DEV__) {
70
+ die("Invalid arguments for `action`")
71
+ }
67
72
  } as IActionFactory
68
73
  return res
69
74
  }
@@ -32,8 +32,7 @@ export type AnnotationMapEntry =
32
32
  // declare annotations for private/ protected members, see #2339
33
33
  export type AnnotationsMap<T, AdditionalFields extends PropertyKey> = {
34
34
  [P in Exclude<keyof T, "toString">]?: AnnotationMapEntry
35
- } &
36
- Record<AdditionalFields, AnnotationMapEntry>
35
+ } & Record<AdditionalFields, AnnotationMapEntry>
37
36
 
38
37
  export function isAnnotation(thing: any) {
39
38
  return (
@@ -38,8 +38,12 @@ export function autorun(
38
38
  opts: IAutorunOptions = EMPTY_OBJECT
39
39
  ): IReactionDisposer {
40
40
  if (__DEV__) {
41
- if (!isFunction(view)) die("Autorun expects a function as first argument")
42
- if (isAction(view)) die("Autorun does not accept actions since actions are untrackable")
41
+ if (!isFunction(view)) {
42
+ die("Autorun expects a function as first argument")
43
+ }
44
+ if (isAction(view)) {
45
+ die("Autorun does not accept actions since actions are untrackable")
46
+ }
43
47
  }
44
48
 
45
49
  const name: string =
@@ -69,7 +73,9 @@ export function autorun(
69
73
  isScheduled = true
70
74
  scheduler(() => {
71
75
  isScheduled = false
72
- if (!reaction.isDisposed_) reaction.track(reactionRunner)
76
+ if (!reaction.isDisposed_) {
77
+ reaction.track(reactionRunner)
78
+ }
73
79
  })
74
80
  }
75
81
  },
@@ -111,9 +117,12 @@ export function reaction<T, FireImmediately extends boolean = false>(
111
117
  opts: IReactionOptions<T, FireImmediately> = EMPTY_OBJECT
112
118
  ): IReactionDisposer {
113
119
  if (__DEV__) {
114
- if (!isFunction(expression) || !isFunction(effect))
120
+ if (!isFunction(expression) || !isFunction(effect)) {
115
121
  die("First and second argument to reaction should be functions")
116
- if (!isPlainObject(opts)) die("Third argument of reactions should be an object")
122
+ }
123
+ if (!isPlainObject(opts)) {
124
+ die("Third argument of reactions should be an object")
125
+ }
117
126
  }
118
127
  const name = opts.name ?? (__DEV__ ? "Reaction@" + getNextId() : "Reaction")
119
128
  const effectAction = action(
@@ -148,7 +157,9 @@ export function reaction<T, FireImmediately extends boolean = false>(
148
157
 
149
158
  function reactionRunner() {
150
159
  isScheduled = false
151
- if (r.isDisposed_) return
160
+ if (r.isDisposed_) {
161
+ return
162
+ }
152
163
  let changed: boolean = false
153
164
  r.track(() => {
154
165
  const nextValue = allowStateChanges(false, () => expression(r))
@@ -159,8 +170,11 @@ export function reaction<T, FireImmediately extends boolean = false>(
159
170
 
160
171
  // This casting is nesessary as TS cannot infer proper type in current funciton implementation
161
172
  type OldValue = FireImmediately extends true ? T | undefined : T
162
- if (firstTime && opts.fireImmediately!) effectAction(value, oldValue as OldValue, r)
163
- else if (!firstTime && changed) effectAction(value, oldValue as OldValue, r)
173
+ if (firstTime && opts.fireImmediately!) {
174
+ effectAction(value, oldValue as OldValue, r)
175
+ } else if (!firstTime && changed) {
176
+ effectAction(value, oldValue as OldValue, r)
177
+ }
164
178
  firstTime = false
165
179
  }
166
180
 
@@ -46,11 +46,14 @@ export const computed: IComputedFactory = function computed(arg1, arg2) {
46
46
 
47
47
  // computed(expr, options?)
48
48
  if (__DEV__) {
49
- if (!isFunction(arg1)) die("First argument to `computed` should be an expression.")
50
- if (isFunction(arg2))
49
+ if (!isFunction(arg1)) {
50
+ die("First argument to `computed` should be an expression.")
51
+ }
52
+ if (isFunction(arg2)) {
51
53
  die(
52
54
  "A setter as second argument is no longer supported, use `{ set: fn }` option instead"
53
55
  )
56
+ }
54
57
  }
55
58
  const opts: IComputedValueOptions<any> = isPlainObject(arg2) ? arg2 : {}
56
59
  opts.get = arg1
@@ -34,7 +34,9 @@ export function configure(options: {
34
34
  ? false
35
35
  : typeof Proxy !== "undefined"
36
36
  }
37
- if (useProxies === "ifavailable") globalState.verifyProxies = true
37
+ if (useProxies === "ifavailable") {
38
+ globalState.verifyProxies = true
39
+ }
38
40
  if (enforceActions !== undefined) {
39
41
  const ea = enforceActions === ALWAYS ? ALWAYS : enforceActions === OBSERVED
40
42
  globalState.enforceActions = ea
@@ -47,7 +49,9 @@ export function configure(options: {
47
49
  "disableErrorBoundaries",
48
50
  "safeDescriptors"
49
51
  ].forEach(key => {
50
- if (key in options) globalState[key] = !!options[key]
52
+ if (key in options) {
53
+ globalState[key] = !!options[key]
54
+ }
51
55
  })
52
56
  globalState.allowStateReads = !globalState.observableRequiresReaction
53
57
  if (__DEV__ && globalState.disableErrorBoundaries === true) {
@@ -21,15 +21,21 @@ export function extendObservable<A extends Object, B extends Object>(
21
21
  options?: CreateObservableOptions
22
22
  ): A & B {
23
23
  if (__DEV__) {
24
- if (arguments.length > 4) die("'extendObservable' expected 2-4 arguments")
25
- if (typeof target !== "object")
24
+ if (arguments.length > 4) {
25
+ die("'extendObservable' expected 2-4 arguments")
26
+ }
27
+ if (typeof target !== "object") {
26
28
  die("'extendObservable' expects an object as first argument")
27
- if (isObservableMap(target))
29
+ }
30
+ if (isObservableMap(target)) {
28
31
  die("'extendObservable' should not be used on maps, use map.merge instead")
29
- if (!isPlainObject(properties))
32
+ }
33
+ if (!isPlainObject(properties)) {
30
34
  die(`'extendObservable' only accepts plain objects as second argument`)
31
- if (isObservable(properties) || isObservable(annotations))
35
+ }
36
+ if (isObservable(properties) || isObservable(annotations)) {
32
37
  die(`Extending an object with another observable (object) is not supported`)
38
+ }
33
39
  }
34
40
  // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
35
41
  const descriptors = getOwnPropertyDescriptors(properties)
package/src/api/extras.ts CHANGED
@@ -18,8 +18,9 @@ function nodeToDependencyTree(node: IDepTreeNode): IDependencyTree {
18
18
  const result: IDependencyTree = {
19
19
  name: node.name_
20
20
  }
21
- if (node.observing_ && node.observing_.length > 0)
21
+ if (node.observing_ && node.observing_.length > 0) {
22
22
  result.dependencies = unique(node.observing_).map(nodeToDependencyTree)
23
+ }
23
24
  return result
24
25
  }
25
26
 
@@ -31,8 +32,9 @@ function nodeToObserverTree(node: IDepTreeNode): IObserverTree {
31
32
  const result: IObserverTree = {
32
33
  name: node.name_
33
34
  }
34
- if (hasObservers(node as any))
35
+ if (hasObservers(node as any)) {
35
36
  result.observers = Array.from(<any>getObservers(node as any)).map(<any>nodeToObserverTree)
37
+ }
36
38
  return result
37
39
  }
38
40
 
package/src/api/flow.ts CHANGED
@@ -42,8 +42,9 @@ export const flow: Flow = Object.assign(
42
42
  return storeAnnotation(arg1, arg2, flowAnnotation)
43
43
  }
44
44
  // flow(fn)
45
- if (__DEV__ && arguments.length !== 1)
45
+ if (__DEV__ && arguments.length !== 1) {
46
46
  die(`Flow expects single argument with generator function`)
47
+ }
47
48
  const generator = arg1
48
49
  const name = generator.name || "<unnamed flow>"
49
50
 
@@ -95,7 +96,9 @@ export const flow: Flow = Object.assign(
95
96
  ret.then(next, reject)
96
97
  return
97
98
  }
98
- if (ret.done) return resolve(ret.value)
99
+ if (ret.done) {
100
+ return resolve(ret.value)
101
+ }
99
102
  pendingPromise = Promise.resolve(ret.value) as any
100
103
  return pendingPromise!.then(onFulfilled, onRejected)
101
104
  }
@@ -105,7 +108,9 @@ export const flow: Flow = Object.assign(
105
108
 
106
109
  promise.cancel = action(`${name} - runid: ${runId} - cancel`, function () {
107
110
  try {
108
- if (pendingPromise) cancelPromise(pendingPromise)
111
+ if (pendingPromise) {
112
+ cancelPromise(pendingPromise)
113
+ }
109
114
  // Finally block can return (or yield) stuff..
110
115
  const res = gen.return!(undefined as any)
111
116
  // eat anything that promise would do, it's cancelled!
@@ -129,7 +134,9 @@ export const flow: Flow = Object.assign(
129
134
  flow.bound = createDecoratorAnnotation(flowBoundAnnotation)
130
135
 
131
136
  function cancelPromise(promise) {
132
- if (isFunction(promise.cancel)) promise.cancel()
137
+ if (isFunction(promise.cancel)) {
138
+ promise.cancel()
139
+ }
133
140
  }
134
141
 
135
142
  export function flowResult<T>(
@@ -39,16 +39,18 @@ export function interceptReads(thing, propOrHandler?, handler?): Lambda {
39
39
  if (isObservableMap(thing) || isObservableArray(thing) || isObservableValue(thing)) {
40
40
  target = getAdministration(thing)
41
41
  } else if (isObservableObject(thing)) {
42
- if (__DEV__ && !isStringish(propOrHandler))
42
+ if (__DEV__ && !isStringish(propOrHandler)) {
43
43
  return die(
44
44
  `InterceptReads can only be used with a specific property, not with an object in general`
45
45
  )
46
+ }
46
47
  target = getAdministration(thing, propOrHandler)
47
48
  } else if (__DEV__) {
48
49
  return die(`Expected observable map, object or array as first array`)
49
50
  }
50
- if (__DEV__ && target.dehancer !== undefined)
51
+ if (__DEV__ && target.dehancer !== undefined) {
51
52
  return die(`An intercept reader was already established`)
53
+ }
52
54
  target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler
53
55
  return () => {
54
56
  target.dehancer = undefined
@@ -43,8 +43,11 @@ export function intercept<T extends object, K extends keyof T>(
43
43
  handler: IInterceptor<IValueWillChange<T[K]>>
44
44
  ): Lambda
45
45
  export function intercept(thing, propOrHandler?, handler?): Lambda {
46
- if (isFunction(handler)) return interceptProperty(thing, propOrHandler, handler)
47
- else return interceptInterceptable(thing, propOrHandler)
46
+ if (isFunction(handler)) {
47
+ return interceptProperty(thing, propOrHandler, handler)
48
+ } else {
49
+ return interceptInterceptable(thing, propOrHandler)
50
+ }
48
51
  }
49
52
 
50
53
  function interceptInterceptable(thing, handler) {
@@ -4,22 +4,28 @@ export function _isComputed(value, property?: PropertyKey): boolean {
4
4
  if (property === undefined) {
5
5
  return isComputedValue(value)
6
6
  }
7
- if (isObservableObject(value) === false) return false
8
- if (!value[$mobx].values_.has(property)) return false
7
+ if (isObservableObject(value) === false) {
8
+ return false
9
+ }
10
+ if (!value[$mobx].values_.has(property)) {
11
+ return false
12
+ }
9
13
  const atom = getAtom(value, property)
10
14
  return isComputedValue(atom)
11
15
  }
12
16
 
13
17
  export function isComputed(value: any): boolean {
14
- if (__DEV__ && arguments.length > 1)
18
+ if (__DEV__ && arguments.length > 1) {
15
19
  return die(
16
20
  `isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property`
17
21
  )
22
+ }
18
23
  return _isComputed(value)
19
24
  }
20
25
 
21
26
  export function isComputedProp(value: any, propName: PropertyKey): boolean {
22
- if (__DEV__ && !isStringish(propName))
27
+ if (__DEV__ && !isStringish(propName)) {
23
28
  return die(`isComputed expected a property name as second argument`)
29
+ }
24
30
  return _isComputed(value, propName)
25
31
  }
@@ -11,12 +11,15 @@ import {
11
11
  } from "../internal"
12
12
 
13
13
  function _isObservable(value, property?: PropertyKey): boolean {
14
- if (!value) return false
14
+ if (!value) {
15
+ return false
16
+ }
15
17
  if (property !== undefined) {
16
- if (__DEV__ && (isObservableMap(value) || isObservableArray(value)))
18
+ if (__DEV__ && (isObservableMap(value) || isObservableArray(value))) {
17
19
  return die(
18
20
  "isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead."
19
21
  )
22
+ }
20
23
  if (isObservableObject(value)) {
21
24
  return value[$mobx].values_.has(property)
22
25
  }
@@ -33,14 +36,17 @@ function _isObservable(value, property?: PropertyKey): boolean {
33
36
  }
34
37
 
35
38
  export function isObservable(value: any): boolean {
36
- if (__DEV__ && arguments.length !== 1)
39
+ if (__DEV__ && arguments.length !== 1) {
37
40
  die(
38
41
  `isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property`
39
42
  )
43
+ }
40
44
  return _isObservable(value)
41
45
  }
42
46
 
43
47
  export function isObservableProp(value: any, propName: PropertyKey): boolean {
44
- if (__DEV__ && !isStringish(propName)) return die(`expected a property name as second argument`)
48
+ if (__DEV__ && !isStringish(propName)) {
49
+ return die(`expected a property name as second argument`)
50
+ }
45
51
  return _isObservable(value, propName)
46
52
  }
@@ -56,10 +56,12 @@ export function makeAutoObservable<T extends object, AdditionalKeys extends Prop
56
56
  options?: CreateObservableOptions
57
57
  ): T {
58
58
  if (__DEV__) {
59
- if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target)))
59
+ if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) {
60
60
  die(`'makeAutoObservable' can only be used for classes that don't have a superclass`)
61
- if (isObservableObject(target))
61
+ }
62
+ if (isObservableObject(target)) {
62
63
  die(`makeAutoObservable can only be used on objects not already made observable`)
64
+ }
63
65
  }
64
66
 
65
67
  // Optimization: avoid visiting protos
@@ -20,9 +20,9 @@ export function keys<T>(set: ObservableSet<T>): ReadonlyArray<T>
20
20
  export function keys<T extends Object>(obj: T): ReadonlyArray<PropertyKey>
21
21
  export function keys(obj: any): any {
22
22
  if (isObservableObject(obj)) {
23
- return (((obj as any) as IIsObservableObject)[
24
- $mobx
25
- ] as ObservableObjectAdministration).keys_()
23
+ return (
24
+ (obj as any as IIsObservableObject)[$mobx] as ObservableObjectAdministration
25
+ ).keys_()
26
26
  }
27
27
  if (isObservableMap(obj) || isObservableSet(obj)) {
28
28
  return Array.from(obj.keys())
@@ -86,26 +86,36 @@ export function set(obj: any, key: any, value?: any): void {
86
86
  startBatch()
87
87
  const values = key
88
88
  try {
89
- for (let key in values) set(obj, key, values[key])
89
+ for (let key in values) {
90
+ set(obj, key, values[key])
91
+ }
90
92
  } finally {
91
93
  endBatch()
92
94
  }
93
95
  return
94
96
  }
95
97
  if (isObservableObject(obj)) {
96
- ;((obj as any) as IIsObservableObject)[$mobx].set_(key, value)
98
+ ;(obj as any as IIsObservableObject)[$mobx].set_(key, value)
97
99
  } else if (isObservableMap(obj)) {
98
100
  obj.set(key, value)
99
101
  } else if (isObservableSet(obj)) {
100
102
  obj.add(key)
101
103
  } else if (isObservableArray(obj)) {
102
- if (typeof key !== "number") key = parseInt(key, 10)
103
- if (key < 0) die(`Invalid index: '${key}'`)
104
+ if (typeof key !== "number") {
105
+ key = parseInt(key, 10)
106
+ }
107
+ if (key < 0) {
108
+ die(`Invalid index: '${key}'`)
109
+ }
104
110
  startBatch()
105
- if (key >= obj.length) obj.length = key + 1
111
+ if (key >= obj.length) {
112
+ obj.length = key + 1
113
+ }
106
114
  obj[key] = value
107
115
  endBatch()
108
- } else die(8)
116
+ } else {
117
+ die(8)
118
+ }
109
119
  }
110
120
 
111
121
  export function remove<K, V>(obj: ObservableMap<K, V>, key: K)
@@ -114,13 +124,15 @@ export function remove<T>(obj: IObservableArray<T>, index: number)
114
124
  export function remove<T extends Object>(obj: T, key: string)
115
125
  export function remove(obj: any, key: any): void {
116
126
  if (isObservableObject(obj)) {
117
- ;((obj as any) as IIsObservableObject)[$mobx].delete_(key)
127
+ ;(obj as any as IIsObservableObject)[$mobx].delete_(key)
118
128
  } else if (isObservableMap(obj)) {
119
129
  obj.delete(key)
120
130
  } else if (isObservableSet(obj)) {
121
131
  obj.delete(key)
122
132
  } else if (isObservableArray(obj)) {
123
- if (typeof key !== "number") key = parseInt(key, 10)
133
+ if (typeof key !== "number") {
134
+ key = parseInt(key, 10)
135
+ }
124
136
  obj.splice(key, 1)
125
137
  } else {
126
138
  die(9)
@@ -133,7 +145,7 @@ export function has<T>(obj: IObservableArray<T>, index: number): boolean
133
145
  export function has<T extends Object>(obj: T, key: string): boolean
134
146
  export function has(obj: any, key: any): boolean {
135
147
  if (isObservableObject(obj)) {
136
- return ((obj as any) as IIsObservableObject)[$mobx].has_(key)
148
+ return (obj as any as IIsObservableObject)[$mobx].has_(key)
137
149
  } else if (isObservableMap(obj)) {
138
150
  return obj.has(key)
139
151
  } else if (isObservableSet(obj)) {
@@ -148,9 +160,11 @@ export function get<K, V>(obj: ObservableMap<K, V>, key: K): V | undefined
148
160
  export function get<T>(obj: IObservableArray<T>, index: number): T | undefined
149
161
  export function get<T extends Object>(obj: T, key: string): any
150
162
  export function get(obj: any, key: any): any {
151
- if (!has(obj, key)) return undefined
163
+ if (!has(obj, key)) {
164
+ return undefined
165
+ }
152
166
  if (isObservableObject(obj)) {
153
- return ((obj as any) as IIsObservableObject)[$mobx].get_(key)
167
+ return (obj as any as IIsObservableObject)[$mobx].get_(key)
154
168
  } else if (isObservableMap(obj)) {
155
169
  return obj.get(key)
156
170
  } else if (isObservableArray(obj)) {
@@ -161,14 +175,14 @@ export function get(obj: any, key: any): any {
161
175
 
162
176
  export function apiDefineProperty(obj: Object, key: PropertyKey, descriptor: PropertyDescriptor) {
163
177
  if (isObservableObject(obj)) {
164
- return ((obj as any) as IIsObservableObject)[$mobx].defineProperty_(key, descriptor)
178
+ return (obj as any as IIsObservableObject)[$mobx].defineProperty_(key, descriptor)
165
179
  }
166
180
  die(39)
167
181
  }
168
182
 
169
183
  export function apiOwnKeys(obj: Object) {
170
184
  if (isObservableObject(obj)) {
171
- return ((obj as any) as IIsObservableObject)[$mobx].ownKeys_()
185
+ return (obj as any as IIsObservableObject)[$mobx].ownKeys_()
172
186
  }
173
187
  die(38)
174
188
  }
@@ -102,22 +102,34 @@ function createObservable(v: any, arg2?: any, arg3?: any) {
102
102
  }
103
103
 
104
104
  // already observable - ignore
105
- if (isObservable(v)) return v
105
+ if (isObservable(v)) {
106
+ return v
107
+ }
106
108
 
107
109
  // plain object
108
- if (isPlainObject(v)) return observable.object(v, arg2, arg3)
110
+ if (isPlainObject(v)) {
111
+ return observable.object(v, arg2, arg3)
112
+ }
109
113
 
110
114
  // Array
111
- if (Array.isArray(v)) return observable.array(v, arg2)
115
+ if (Array.isArray(v)) {
116
+ return observable.array(v, arg2)
117
+ }
112
118
 
113
119
  // Map
114
- if (isES6Map(v)) return observable.map(v, arg2)
120
+ if (isES6Map(v)) {
121
+ return observable.map(v, arg2)
122
+ }
115
123
 
116
124
  // Set
117
- if (isES6Set(v)) return observable.set(v, arg2)
125
+ if (isES6Set(v)) {
126
+ return observable.set(v, arg2)
127
+ }
118
128
 
119
129
  // other object - ignore
120
- if (typeof v === "object" && v !== null) return v
130
+ if (typeof v === "object" && v !== null) {
131
+ return v
132
+ }
121
133
 
122
134
  // anything else
123
135
  return observable.box(v, arg2)
@@ -169,9 +181,11 @@ const observableFactories: IObservableFactory = {
169
181
  },
170
182
  array<T = any>(initialValues?: T[], options?: CreateObservableOptions): IObservableArray<T> {
171
183
  const o = asCreateObservableOptions(options)
172
- return (globalState.useProxies === false || o.proxy === false
173
- ? createLegacyArray
174
- : createObservableArray)(initialValues, getEnhancerFromOptions(o), o.name)
184
+ return (
185
+ globalState.useProxies === false || o.proxy === false
186
+ ? createLegacyArray
187
+ : createObservableArray
188
+ )(initialValues, getEnhancerFromOptions(o), o.name)
175
189
  },
176
190
  map<K = any, V = any>(
177
191
  initialValues?: IObservableMapInitialValues<K, V>,
@@ -53,9 +53,11 @@ export function observe<T, K extends keyof T>(
53
53
  fireImmediately?: boolean
54
54
  ): Lambda
55
55
  export function observe(thing, propOrCb?, cbOrFire?, fireImmediately?): Lambda {
56
- if (isFunction(cbOrFire))
56
+ if (isFunction(cbOrFire)) {
57
57
  return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately)
58
- else return observeObservable(thing, propOrCb, cbOrFire)
58
+ } else {
59
+ return observeObservable(thing, propOrCb, cbOrFire)
60
+ }
59
61
  }
60
62
 
61
63
  function observeObservable(thing, listener, fireImmediately: boolean) {
package/src/api/tojs.ts CHANGED
@@ -21,11 +21,13 @@ function toJSHelper(source, __alreadySeen: Map<any, any>) {
21
21
  typeof source !== "object" ||
22
22
  source instanceof Date ||
23
23
  !isObservable(source)
24
- )
24
+ ) {
25
25
  return source
26
+ }
26
27
 
27
- if (isObservableValue(source) || isComputedValue(source))
28
+ if (isObservableValue(source) || isComputedValue(source)) {
28
29
  return toJSHelper(source.get(), __alreadySeen)
30
+ }
29
31
  if (__alreadySeen.has(source)) {
30
32
  return __alreadySeen.get(source)
31
33
  }
@@ -68,6 +70,8 @@ function toJSHelper(source, __alreadySeen: Map<any, any>) {
68
70
  * Complex scenarios require custom solution, eg implementing `toJSON` or using `serializr` lib.
69
71
  */
70
72
  export function toJS<T>(source: T, options?: any): T {
71
- if (__DEV__ && options) die("toJS no longer supports options")
73
+ if (__DEV__ && options) {
74
+ die("toJS no longer supports options")
75
+ }
72
76
  return toJSHelper(source, new Map())
73
77
  }
package/src/api/trace.ts CHANGED
@@ -4,9 +4,13 @@ export function trace(thing?: any, prop?: string, enterBreakPoint?: boolean): vo
4
4
  export function trace(thing?: any, enterBreakPoint?: boolean): void
5
5
  export function trace(enterBreakPoint?: boolean): void
6
6
  export function trace(...args: any[]): void {
7
- if (!__DEV__) die(`trace() is not available in production builds`)
7
+ if (!__DEV__) {
8
+ die(`trace() is not available in production builds`)
9
+ }
8
10
  let enterBreakPoint = false
9
- if (typeof args[args.length - 1] === "boolean") enterBreakPoint = args.pop()
11
+ if (typeof args[args.length - 1] === "boolean") {
12
+ enterBreakPoint = args.pop()
13
+ }
10
14
  const derivation = getAtomFromArgs(args)
11
15
  if (!derivation) {
12
16
  return die(