mobx 6.11.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/CHANGELOG.md +18 -0
- package/README.md +27 -31
- package/dist/core/atom.d.ts +0 -1
- package/dist/core/globalstate.d.ts +0 -9
- package/dist/mobx.cjs.development.js +19 -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 +19 -22
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +19 -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 +19 -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/package.json +1 -1
- package/src/api/autorun.ts +2 -3
- package/src/core/action.ts +1 -0
- package/src/core/atom.ts +2 -17
- package/src/core/derivation.ts +6 -3
- package/src/core/globalstate.ts +0 -11
- package/src/core/observable.ts +0 -6
- package/src/types/legacyobservablearray.ts +1 -1
- package/src/types/observablearray.ts +9 -2
package/package.json
CHANGED
package/src/api/autorun.ts
CHANGED
|
@@ -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
|
|
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)
|
package/src/core/action.ts
CHANGED
|
@@ -50,6 +50,7 @@ export function createAction(
|
|
|
50
50
|
return executeAction(actionName, autoAction, fn, ref || this, arguments)
|
|
51
51
|
}
|
|
52
52
|
res.isMobxAction = true
|
|
53
|
+
res.toString = () => fn.toString()
|
|
53
54
|
if (isFunctionNameConfigurable) {
|
|
54
55
|
tmpNameDescriptor.value = actionName
|
|
55
56
|
defineProperty(res, "name", tmpNameDescriptor)
|
package/src/core/atom.ts
CHANGED
|
@@ -11,8 +11,7 @@ import {
|
|
|
11
11
|
propagateChanged,
|
|
12
12
|
reportObserved,
|
|
13
13
|
startBatch,
|
|
14
|
-
Lambda
|
|
15
|
-
globalState
|
|
14
|
+
Lambda
|
|
16
15
|
} from "../internal"
|
|
17
16
|
|
|
18
17
|
export const $mobx = Symbol("mobx administration")
|
|
@@ -27,7 +26,6 @@ export class Atom implements IAtom {
|
|
|
27
26
|
isBeingObserved_ = false
|
|
28
27
|
observers_ = new Set<IDerivation>()
|
|
29
28
|
|
|
30
|
-
batchId_: number
|
|
31
29
|
diffValue_ = 0
|
|
32
30
|
lastAccessedBy_ = 0
|
|
33
31
|
lowestObserverState_ = IDerivationState_.NOT_TRACKING_
|
|
@@ -35,9 +33,7 @@ export class Atom implements IAtom {
|
|
|
35
33
|
* Create a new atom. For debugging purposes it is recommended to give it a name.
|
|
36
34
|
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
|
|
37
35
|
*/
|
|
38
|
-
constructor(public name_ = __DEV__ ? "Atom@" + getNextId() : "Atom") {
|
|
39
|
-
this.batchId_ = globalState.inBatch ? globalState.batchId : NaN
|
|
40
|
-
}
|
|
36
|
+
constructor(public name_ = __DEV__ ? "Atom@" + getNextId() : "Atom") {}
|
|
41
37
|
|
|
42
38
|
// onBecomeObservedListeners
|
|
43
39
|
public onBOL: Set<Lambda> | undefined
|
|
@@ -68,17 +64,6 @@ export class Atom implements IAtom {
|
|
|
68
64
|
* Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
|
|
69
65
|
*/
|
|
70
66
|
public reportChanged() {
|
|
71
|
-
if (!globalState.inBatch || this.batchId_ !== globalState.batchId) {
|
|
72
|
-
// We could update state version only at the end of batch,
|
|
73
|
-
// but we would still have to switch some global flag here to signal a change.
|
|
74
|
-
globalState.stateVersion =
|
|
75
|
-
globalState.stateVersion < Number.MAX_SAFE_INTEGER
|
|
76
|
-
? globalState.stateVersion + 1
|
|
77
|
-
: Number.MIN_SAFE_INTEGER
|
|
78
|
-
// Avoids the possibility of hitting the same globalState.batchId when it cycled through all integers (necessary?)
|
|
79
|
-
this.batchId_ = NaN
|
|
80
|
-
}
|
|
81
|
-
|
|
82
67
|
startBatch()
|
|
83
68
|
propagateChanged(this)
|
|
84
69
|
endBatch()
|
package/src/core/derivation.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
package/src/core/globalstate.ts
CHANGED
|
@@ -63,12 +63,6 @@ export class MobXGlobals {
|
|
|
63
63
|
*/
|
|
64
64
|
inBatch: number = 0
|
|
65
65
|
|
|
66
|
-
/**
|
|
67
|
-
* ID of the latest batch. Used to suppress reportChanged of newly created atoms.
|
|
68
|
-
* Note the value persists even after batch ended.
|
|
69
|
-
*/
|
|
70
|
-
batchId: number = Number.MIN_SAFE_INTEGER
|
|
71
|
-
|
|
72
66
|
/**
|
|
73
67
|
* Observables that don't have observers anymore, and are about to be
|
|
74
68
|
* suspended, unless somebody else accesses it in the same batch
|
|
@@ -156,11 +150,6 @@ export class MobXGlobals {
|
|
|
156
150
|
* configurable: true
|
|
157
151
|
*/
|
|
158
152
|
safeDescriptors = true
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Changes with each state update, used by useSyncExternalStore
|
|
162
|
-
*/
|
|
163
|
-
stateVersion = Number.MIN_SAFE_INTEGER
|
|
164
153
|
}
|
|
165
154
|
|
|
166
155
|
let canMergeGlobalState = true
|
package/src/core/observable.ts
CHANGED
|
@@ -104,12 +104,6 @@ export function queueForUnobservation(observable: IObservable) {
|
|
|
104
104
|
* Avoids unnecessary recalculations.
|
|
105
105
|
*/
|
|
106
106
|
export function startBatch() {
|
|
107
|
-
if (globalState.inBatch === 0) {
|
|
108
|
-
globalState.batchId =
|
|
109
|
-
globalState.batchId < Number.MAX_SAFE_INTEGER
|
|
110
|
-
? globalState.batchId + 1
|
|
111
|
-
: Number.MIN_SAFE_INTEGER
|
|
112
|
-
}
|
|
113
107
|
globalState.inBatch++
|
|
114
108
|
}
|
|
115
109
|
|
|
@@ -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
|
|
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
|
}
|
|
@@ -518,6 +518,7 @@ export var arrayExtensions = {
|
|
|
518
518
|
* Without this, everything works as well, but this works
|
|
519
519
|
* faster as everything works on unproxied values
|
|
520
520
|
*/
|
|
521
|
+
addArrayExtension("at", simpleFunc)
|
|
521
522
|
addArrayExtension("concat", simpleFunc)
|
|
522
523
|
addArrayExtension("flat", simpleFunc)
|
|
523
524
|
addArrayExtension("includes", simpleFunc)
|
|
@@ -527,15 +528,21 @@ addArrayExtension("lastIndexOf", simpleFunc)
|
|
|
527
528
|
addArrayExtension("slice", simpleFunc)
|
|
528
529
|
addArrayExtension("toString", simpleFunc)
|
|
529
530
|
addArrayExtension("toLocaleString", simpleFunc)
|
|
531
|
+
addArrayExtension("toSorted", simpleFunc)
|
|
532
|
+
addArrayExtension("toSpliced", simpleFunc)
|
|
533
|
+
addArrayExtension("with", simpleFunc)
|
|
530
534
|
// map
|
|
531
535
|
addArrayExtension("every", mapLikeFunc)
|
|
532
536
|
addArrayExtension("filter", mapLikeFunc)
|
|
533
537
|
addArrayExtension("find", mapLikeFunc)
|
|
534
538
|
addArrayExtension("findIndex", mapLikeFunc)
|
|
539
|
+
addArrayExtension("findLast", mapLikeFunc)
|
|
540
|
+
addArrayExtension("findLastIndex", mapLikeFunc)
|
|
535
541
|
addArrayExtension("flatMap", mapLikeFunc)
|
|
536
542
|
addArrayExtension("forEach", mapLikeFunc)
|
|
537
543
|
addArrayExtension("map", mapLikeFunc)
|
|
538
544
|
addArrayExtension("some", mapLikeFunc)
|
|
545
|
+
addArrayExtension("toReversed", mapLikeFunc)
|
|
539
546
|
// reduce
|
|
540
547
|
addArrayExtension("reduce", reduceLikeFunc)
|
|
541
548
|
addArrayExtension("reduceRight", reduceLikeFunc)
|
|
@@ -556,7 +563,7 @@ function simpleFunc(funcName) {
|
|
|
556
563
|
}
|
|
557
564
|
}
|
|
558
565
|
|
|
559
|
-
// Make sure callbacks
|
|
566
|
+
// Make sure callbacks receive correct array arg #2326
|
|
560
567
|
function mapLikeFunc(funcName) {
|
|
561
568
|
return function (callback, thisArg) {
|
|
562
569
|
const adm: ObservableArrayAdministration = this[$mobx]
|
|
@@ -568,7 +575,7 @@ function mapLikeFunc(funcName) {
|
|
|
568
575
|
}
|
|
569
576
|
}
|
|
570
577
|
|
|
571
|
-
// Make sure callbacks
|
|
578
|
+
// Make sure callbacks receive correct array arg #2326
|
|
572
579
|
function reduceLikeFunc(funcName) {
|
|
573
580
|
return function () {
|
|
574
581
|
const adm: ObservableArrayAdministration = this[$mobx]
|