mobx 7.0.3 → 7.0.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 +16 -0
- package/dist/api/makeObservable.d.ts +0 -2
- package/dist/core/reaction.d.ts +1 -1
- package/dist/mobx.cjs.development.js +64 -31
- 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 +64 -31
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +64 -31
- 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.mjs +64 -31
- package/dist/mobx.mjs.map +1 -1
- package/dist/mobx.umd.development.js +64 -31
- 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/autoannotation.d.ts +2 -1
- package/package.json +1 -1
- package/src/api/makeObservable.ts +0 -7
- package/src/api/observable.ts +2 -2
- package/src/core/computedvalue.ts +4 -1
- package/src/core/observable.ts +33 -25
- package/src/core/reaction.ts +1 -1
- package/src/types/autoannotation.ts +13 -1
- package/src/types/intercept-utils.ts +7 -2
- package/src/types/listen-utils.ts +7 -2
|
@@ -816,6 +816,19 @@ function createAutoAnnotation(options) {
|
|
|
816
816
|
extend_
|
|
817
817
|
};
|
|
818
818
|
}
|
|
819
|
+
// The auto annotation only depends on `deep` and `autoBind`, so share one instance per combination
|
|
820
|
+
// instead of allocating one for every object created with options
|
|
821
|
+
const autoAnnotations = [autoAnnotation];
|
|
822
|
+
function getAutoAnnotation(options) {
|
|
823
|
+
var _autoAnnotations$idx;
|
|
824
|
+
const deep = options.deep !== false;
|
|
825
|
+
const autoBind = !!options.autoBind;
|
|
826
|
+
const idx = (deep ? 0 : 1) | (autoBind ? 2 : 0);
|
|
827
|
+
return (_autoAnnotations$idx = autoAnnotations[idx]) != null ? _autoAnnotations$idx : autoAnnotations[idx] = createAutoAnnotation({
|
|
828
|
+
deep,
|
|
829
|
+
autoBind
|
|
830
|
+
});
|
|
831
|
+
}
|
|
819
832
|
function make_$1(adm, key, descriptor, source) {
|
|
820
833
|
var _this$options_3, _this$options_4;
|
|
821
834
|
// getter -> computed
|
|
@@ -932,7 +945,7 @@ function getEnhancerFromOptions(options) {
|
|
|
932
945
|
}
|
|
933
946
|
function getAnnotationFromOptions(options) {
|
|
934
947
|
var _options$defaultDecor;
|
|
935
|
-
return options ? (_options$defaultDecor = options.defaultDecorator) != null ? _options$defaultDecor :
|
|
948
|
+
return options ? (_options$defaultDecor = options.defaultDecorator) != null ? _options$defaultDecor : getAutoAnnotation(options) : undefined;
|
|
936
949
|
}
|
|
937
950
|
function getEnhancerFromAnnotation(annotation) {
|
|
938
951
|
var _annotation$options_$, _annotation$options_;
|
|
@@ -1384,7 +1397,10 @@ class ComputedValue {
|
|
|
1384
1397
|
reportObserved(this);
|
|
1385
1398
|
if (shouldCompute(this)) {
|
|
1386
1399
|
let prevTrackingContext = globalState.trackingContext;
|
|
1387
|
-
if (this.keepAlive_
|
|
1400
|
+
if (!prevTrackingContext && (this.keepAlive_ || this.isBeingObserved)) {
|
|
1401
|
+
// An observed or keep-alive computed can be recomputed by an untracked
|
|
1402
|
+
// read, for example from inside an action. Its dependencies are still
|
|
1403
|
+
// transitively observed and must fire their lifecycle hooks
|
|
1388
1404
|
globalState.trackingContext = this;
|
|
1389
1405
|
}
|
|
1390
1406
|
if (this.trackAndCompute()) {
|
|
@@ -1981,34 +1997,41 @@ function endBatch() {
|
|
|
1981
1997
|
// the nested call instead of recursing; the outer loop re-reads list.length on
|
|
1982
1998
|
// every iteration, so it picks up anything the nested dispose() pushes onto the
|
|
1983
1999
|
// same pendingUnobservations array.
|
|
1984
|
-
if (!globalState.isRunningUnobservations) {
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2000
|
+
if (!globalState.isRunningUnobservations && globalState.pendingUnobservations.length > 0) {
|
|
2001
|
+
runPendingUnobservations();
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
// Only called when there is something to unobserve, so the common endBatch() skips the
|
|
2006
|
+
// try/finally and the pendingUnobservations reallocation entirely
|
|
2007
|
+
function runPendingUnobservations() {
|
|
2008
|
+
globalState.isRunningUnobservations = true;
|
|
2009
|
+
try {
|
|
2010
|
+
const list = globalState.pendingUnobservations;
|
|
2011
|
+
for (let i = 0; i < list.length; i++) {
|
|
2012
|
+
const observable = list[i];
|
|
2013
|
+
observable.isPendingUnobservation = false;
|
|
2014
|
+
if (!observable.observers_ || observable.observers_.size === 0) {
|
|
2015
|
+
// release the empty Set so unobserved atoms don't keep paying for it
|
|
2016
|
+
observable.observers_ = null;
|
|
2017
|
+
if (observable.isBeingObserved) {
|
|
2018
|
+
// if this observable had reactive observers, trigger the hooks
|
|
2019
|
+
observable.isBeingObserved = false;
|
|
2020
|
+
observable.onBUO();
|
|
2021
|
+
}
|
|
2022
|
+
if (observable instanceof ComputedValue) {
|
|
2023
|
+
// computed values are automatically teared down when the last observer leaves
|
|
2024
|
+
// this process happens recursively, this computed might be the last observabe of another, etc..
|
|
2025
|
+
observable.suspend_();
|
|
2003
2026
|
}
|
|
2004
|
-
globalState.pendingUnobservations = [];
|
|
2005
|
-
} finally {
|
|
2006
|
-
// Always release the guard, even if an onBUO handler (user code) threw,
|
|
2007
|
-
// otherwise every future endBatch() would see isRunningUnobservations
|
|
2008
|
-
// stuck true and silently stop draining pendingUnobservations forever.
|
|
2009
|
-
globalState.isRunningUnobservations = false;
|
|
2010
2027
|
}
|
|
2011
2028
|
}
|
|
2029
|
+
globalState.pendingUnobservations = [];
|
|
2030
|
+
} finally {
|
|
2031
|
+
// Always release the guard, even if an onBUO handler (user code) threw,
|
|
2032
|
+
// otherwise every future endBatch() would see isRunningUnobservations
|
|
2033
|
+
// stuck true and silently stop draining pendingUnobservations forever.
|
|
2034
|
+
globalState.isRunningUnobservations = false;
|
|
2012
2035
|
}
|
|
2013
2036
|
}
|
|
2014
2037
|
/**
|
|
@@ -3287,8 +3310,13 @@ function hasInterceptors(interceptable) {
|
|
|
3287
3310
|
return interceptable.interceptors_ !== undefined && interceptable.interceptors_.length > 0;
|
|
3288
3311
|
}
|
|
3289
3312
|
function registerInterceptor(interceptable, handler) {
|
|
3290
|
-
|
|
3291
|
-
interceptors
|
|
3313
|
+
let interceptors = interceptable.interceptors_;
|
|
3314
|
+
if (interceptors) {
|
|
3315
|
+
interceptors.push(handler);
|
|
3316
|
+
} else {
|
|
3317
|
+
// Allocate at the exact size: pushing onto an empty array over-allocates its backing store
|
|
3318
|
+
interceptors = interceptable.interceptors_ = [handler];
|
|
3319
|
+
}
|
|
3292
3320
|
return once(() => {
|
|
3293
3321
|
const idx = interceptors.indexOf(handler);
|
|
3294
3322
|
if (idx !== -1) {
|
|
@@ -3320,8 +3348,13 @@ function hasListeners(listenable) {
|
|
|
3320
3348
|
return listenable.changeListeners_ !== undefined && listenable.changeListeners_.length > 0;
|
|
3321
3349
|
}
|
|
3322
3350
|
function registerListener(listenable, handler) {
|
|
3323
|
-
|
|
3324
|
-
listeners
|
|
3351
|
+
let listeners = listenable.changeListeners_;
|
|
3352
|
+
if (listeners) {
|
|
3353
|
+
listeners.push(handler);
|
|
3354
|
+
} else {
|
|
3355
|
+
// Allocate at the exact size: pushing onto an empty array over-allocates its backing store
|
|
3356
|
+
listeners = listenable.changeListeners_ = [handler];
|
|
3357
|
+
}
|
|
3325
3358
|
return once(() => {
|
|
3326
3359
|
const idx = listeners.indexOf(handler);
|
|
3327
3360
|
if (idx !== -1) {
|