mobx 6.12.0 → 6.12.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx",
3
- "version": "6.12.0",
3
+ "version": "6.12.1",
4
4
  "description": "Simple, scalable state management.",
5
5
  "source": "src/mobx.ts",
6
6
  "main": "dist/index.js",
@@ -139,7 +139,6 @@ export function reaction<T, FireImmediately extends boolean = false>(
139
139
  let firstTime = true
140
140
  let isScheduled = false
141
141
  let value: T
142
- let oldValue: T | undefined
143
142
 
144
143
  const equals: IEqualsComparer<T> = (opts as any).compareStructural
145
144
  ? comparer.structural
@@ -165,14 +164,14 @@ export function reaction<T, FireImmediately extends boolean = false>(
165
164
  return
166
165
  }
167
166
  let changed: boolean = false
167
+ const oldValue = value
168
168
  r.track(() => {
169
169
  const nextValue = allowStateChanges(false, () => expression(r))
170
170
  changed = firstTime || !equals(value, nextValue)
171
- oldValue = value
172
171
  value = nextValue
173
172
  })
174
173
 
175
- // This casting is nesessary as TS cannot infer proper type in current funciton implementation
174
+ // This casting is nesessary as TS cannot infer proper type in current function implementation
176
175
  type OldValue = FireImmediately extends true ? T | undefined : T
177
176
  if (firstTime && opts.fireImmediately!) {
178
177
  effectAction(value, oldValue as OldValue, r)
@@ -166,10 +166,13 @@ export function checkIfStateReadsAreAllowed(observable: IObservable) {
166
166
  */
167
167
  export function trackDerivedFunction<T>(derivation: IDerivation, f: () => T, context: any) {
168
168
  const prevAllowStateReads = allowStateReadsStart(true)
169
- // pre allocate array allocation + room for variation in deps
170
- // array will be trimmed by bindDependencies
171
169
  changeDependenciesStateTo0(derivation)
172
- derivation.newObserving_ = new Array(derivation.observing_.length + 100)
170
+ // Preallocate array; will be trimmed by bindDependencies.
171
+ derivation.newObserving_ = new Array(
172
+ // Reserve constant space for initial dependencies, dynamic space otherwise.
173
+ // See https://github.com/mobxjs/mobx/pull/3833
174
+ derivation.runId_ === 0 ? 100 : derivation.observing_.length
175
+ )
173
176
  derivation.unboundDepsCount_ = 0
174
177
  derivation.runId_ = ++globalState.runId
175
178
  const prevTracking = globalState.trackingDerivation
@@ -71,7 +71,7 @@ export class LegacyObservableArray<T> extends StubArray {
71
71
  }
72
72
 
73
73
  if (safariPrototypeSetterInheritanceBug) {
74
- // Seems that Safari won't use numeric prototype setter untill any * numeric property is
74
+ // Seems that Safari won't use numeric prototype setter until any * numeric property is
75
75
  // defined on the instance. After that it works fine, even if this property is deleted.
76
76
  Object.defineProperty(this, "0", ENTRY_0)
77
77
  }
@@ -563,7 +563,7 @@ function simpleFunc(funcName) {
563
563
  }
564
564
  }
565
565
 
566
- // Make sure callbacks recieve correct array arg #2326
566
+ // Make sure callbacks receive correct array arg #2326
567
567
  function mapLikeFunc(funcName) {
568
568
  return function (callback, thisArg) {
569
569
  const adm: ObservableArrayAdministration = this[$mobx]
@@ -575,7 +575,7 @@ function mapLikeFunc(funcName) {
575
575
  }
576
576
  }
577
577
 
578
- // Make sure callbacks recieve correct array arg #2326
578
+ // Make sure callbacks receive correct array arg #2326
579
579
  function reduceLikeFunc(funcName) {
580
580
  return function () {
581
581
  const adm: ObservableArrayAdministration = this[$mobx]