mobx 6.11.0-pre → 6.12.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.
- package/CHANGELOG.md +19 -0
- package/README.md +28 -32
- package/dist/core/atom.d.ts +0 -1
- package/dist/core/globalstate.d.ts +0 -9
- package/dist/mobx.cjs.development.js +18 -25
- 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 +18 -25
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +18 -25
- 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 +18 -25
- 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/observableobject.d.ts +0 -1
- package/package.json +1 -1
- package/src/api/decorators.ts +5 -1
- package/src/api/observable.ts +1 -0
- package/src/core/action.ts +1 -0
- package/src/core/atom.ts +2 -17
- package/src/core/globalstate.ts +0 -11
- package/src/core/observable.ts +0 -6
- package/src/types/observableannotation.ts +12 -12
- package/src/types/observablearray.ts +7 -0
- package/src/types/observableobject.ts +0 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# mobx
|
|
2
2
|
|
|
3
|
+
## 6.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`ec5db592`](https://github.com/mobxjs/mobx/commit/ec5db592d7756826c31e710b1c759d7e9406b153) [#3792](https://github.com/mobxjs/mobx/pull/3792) Thanks [@tonyraoul](https://github.com/tonyraoul)! - Improve observablearray proxy pefromance for es2023.array and es2022.array methods
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [`86616c11`](https://github.com/mobxjs/mobx/commit/86616c11c108a511331eb05e55c08fc2c5a23f4d) [#3654](https://github.com/mobxjs/mobx/pull/3654) Thanks [@ahoisl](https://github.com/ahoisl)! - fix: action transparently forwards toString of underlying function
|
|
12
|
+
|
|
13
|
+
## 6.11.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [`c9260974`](https://github.com/mobxjs/mobx/commit/c9260974f726f58de0fd4974ea024c644d9b7c6f) [#3790](https://github.com/mobxjs/mobx/pull/3790) Thanks [@mweststrate](https://github.com/mweststrate)! - Added support for modern 2022.3 Decorators. [#3790](https://github.com/mobxjs/mobx/pull/3790)
|
|
18
|
+
- [Installation / usage instruction](https://mobx.js.org/enabling-decorators.html).
|
|
19
|
+
- [Introduction announcement](https://michel.codes/blogs/mobx-decorators)
|
|
20
|
+
- Original PR by [@Matchlighter](https://github.com/Matchlighter) in [#3638](https://github.com/mobxjs/mobx/pull/3638),
|
|
21
|
+
|
|
3
22
|
## 6.10.2
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -23,42 +23,42 @@ Documentation can be found at **[mobx.js.org](https://mobx.js.org/)**.
|
|
|
23
23
|
|
|
24
24
|
MobX is made possible by the generosity of the sponsors below, and many other [individual backers](https://github.com/mobxjs/mobx/blob/main/docs/backers-sponsors.md#backers). Sponsoring directly impacts the longevity of this project.
|
|
25
25
|
|
|
26
|
-
**🥇 Gold sponsors (\$
|
|
27
|
-
|
|
26
|
+
**🥇 Gold sponsors (\$2500+ total contribution):**
|
|
27
|
+
|
|
28
|
+
<br/>
|
|
28
29
|
<a href="https://www.guilded.gg/"><img src="https://mobx.js.org/assets/guilded.jpg" align="center" width="100" title="Guilded" alt="Guilded" /></a>
|
|
29
30
|
<a href="https://www.getparallax.com/"><img src="https://mobx.js.org/assets/parallax.png" align="center" width="100" title="Parallax" alt="Parallax" /></a>
|
|
30
|
-
<a href="https://frontendmasters.com/"><img src="https://mobx.js.org/assets/frontendmasters.jpg" align="center" width="100" title="Frontend Masters" alt="Frontend Masters"></a>
|
|
31
31
|
<a href="https://www.one-beyond.com"><img src="https://mobx.js.org/assets/dcsl.png" align="center" width="100" title="One Beyond" alt="One Beyond"/></a>
|
|
32
|
+
<a href="https://frontendmasters.com/"><img src="https://mobx.js.org/assets/frontendmasters.jpg" align="center" width="100" title="Frontend Masters" alt="Frontend Masters"></a>
|
|
32
33
|
<a href="http://auctionfrontier.com/"><img src="https://mobx.js.org/assets/auctionfrontier.jpeg" align="center" width="100" title="Auction Frontier" alt="Auction Frontier"></a>
|
|
33
34
|
<a href="https://www.codefirst.co.uk/"><img src="https://mobx.js.org/assets/codefirst.png" align="center" width="100" title="CodeFirst" alt="CodeFirst"/></a>
|
|
34
35
|
<a href="https://modulz.app/"><img src="https://mobx.js.org/assets/modulz.png" align="center" width="100" title="Modulz" alt="Modulz"/></a>
|
|
35
36
|
<a href="https://coinbase.com/"><img src="https://mobx.js.org/assets/coinbase.jpeg" align="center" width="100" title="Coinbase" alt="Coinbase" /></a>
|
|
36
37
|
<a href="https://curology.com/blog/tech"><img src="https://mobx.js.org/assets/curology.png" align="center" width="100" title="Curology" alt="Curology"/></a>
|
|
38
|
+
<a href="https://mendix.com/"><img src="https://mobx.js.org/assets/mendix-logo.png" align="center" width="100" title="Mendix" alt="Mendix" /></a>
|
|
39
|
+
<a href="https://www.canva.com/"><img src="https://mobx.js.org/assets/canva.svg" align="center" width="100" title="Canva" alt="Canva" /></a>
|
|
37
40
|
<a href="https://opensource.facebook.com/"><img src="https://mobx.js.org/assets/fbos.jpeg" align="center" width="100" title="Facebook Open Source" alt="Facebook Open Source" /></a>
|
|
38
|
-
<a href="https://www.canva.com/"><img src="https://mobx.js.org/assets/canva.png" align="center" width="100" title="Canva" alt="Canva" /></a>
|
|
39
|
-
|
|
40
|
-
**🥈 Silver sponsors (\$100+ per month):**<br/>
|
|
41
|
-
|
|
42
41
|
<a href="https://casinosites.ltd.uk/?utm_source=sponsorship&utm_medium=mobx&utm_campaign=readme"><img src="https://mobx.js.org/assets/casino2.png" align="center" width="100" title="Casino Sites" alt="Casino Sites"/></a>
|
|
43
|
-
<a href="https://upper.co/?utm_source=github_mobxjs_sponsorship&utm_medium=paid_acquisition&utm_campaign=sponsorship"><img src="https://mobx.js.org/assets/upper.png" align="center" width="100" title="UPPER" alt="UPPER"/></a>
|
|
44
|
-
<a href="https://www.easeus.com/?utm_source=github_mobxjs_sponsorship&utm_medium=readme&utm_campaign=sponsorship"><img src="https://mobx.js.org/assets/easeus.png" align="center" width="100" title="EaseUS" alt="EaseUS"/></a>
|
|
45
|
-
|
|
46
|
-
**🥉 Bronze sponsors (\$500+ total contributions):**<br/>
|
|
47
42
|
<a href="https://www.bugsnag.com/platforms/react-error-reporting?utm_source=MobX&utm_medium=Website&utm_content=open-source&utm_campaign=2019-community&utm_term=20190913"><img src="https://mobx.js.org/assets/bugsnag.jpg" align="center" width="100" title="Bugsnag" alt="Bugsnag"/></a>
|
|
48
|
-
|
|
43
|
+
|
|
44
|
+
**🥈 Silver sponsors (\$500+ total contributions):**<br/>
|
|
45
|
+
|
|
49
46
|
<a href="https://mantro.net/jobs/warlock"><img src="https://mobx.js.org/assets/mantro.png" align="center" width="100" title="mantro GmbH" alt="mantro GmbH"></a>
|
|
47
|
+
<a href="https://www.xh.com/"><img src="https://mobx.js.org/assets/xh.png" align="center" width="100" title="Extremely Heavy" alt="Extremely Heavy" /></a>
|
|
50
48
|
<a href="https://www.algolia.com/"><img src="https://mobx.js.org/assets/algolia.jpg" align="center" width="100" title="Algolia" alt="Algolia" /></a>
|
|
51
|
-
<a href="https://
|
|
52
|
-
<a href="https://careers.dazn.com/"><img src="https://mobx.js.org/assets/dazn.png" align="center" width="100" title="DAZN" alt="DAZN"></a>
|
|
49
|
+
<a href="https://space307.com/?utm_source=sponsorship&utm_medium=mobx&utm_campaign=readme"><img src="https://mobx.js.org/assets/space307.png" align="center" width="100" title="Space307" alt="Space307"/></a>
|
|
53
50
|
<a href="https://blokt.com/"><img src="https://mobx.js.org/assets/blokt.jpg" align="center" width="100" title="Blokt" alt="Blokt"/></a>
|
|
51
|
+
<a href="https://upper.co/?utm_source=github_mobxjs_sponsorship&utm_medium=paid_acquisition&utm_campaign=sponsorship"><img src="https://mobx.js.org/assets/upper.png" align="center" width="100" title="UPPER" alt="UPPER"/></a>
|
|
52
|
+
<a href="https://careers.dazn.com/"><img src="https://mobx.js.org/assets/dazn.png" align="center" width="100" title="DAZN" alt="DAZN"></a>
|
|
53
|
+
<a href="https://talentplot.com/"><img src="https://mobx.js.org/assets/talentplot.png" align="center" width="100" title="talentplot" alt="talentplot"></a>
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
## <a href="https://www.easeus.com/?utm_source=github_mobxjs_sponsorship&utm_medium=readme&utm_campaign=sponsorship"><img src="https://mobx.js.org/assets/easeus.png" align="center" width="100" title="EaseUS" alt="EaseUS"/></a>
|
|
56
56
|
|
|
57
57
|
## Introduction
|
|
58
58
|
|
|
59
59
|
_Anything that can be derived from the application state, should be. Automatically._
|
|
60
60
|
|
|
61
|
-
MobX is a battle-tested library that makes state management simple and scalable by transparently applying functional reactive programming.
|
|
61
|
+
MobX is a signal based, battle-tested library that makes state management simple and scalable by transparently applying functional reactive programming.
|
|
62
62
|
The philosophy behind MobX is simple:
|
|
63
63
|
|
|
64
64
|
<div class="benefits">
|
|
@@ -106,26 +106,22 @@ So what does code that uses MobX look like?
|
|
|
106
106
|
import React from "react"
|
|
107
107
|
import ReactDOM from "react-dom"
|
|
108
108
|
import { makeAutoObservable } from "mobx"
|
|
109
|
-
import { observer } from "mobx-react"
|
|
109
|
+
import { observer } from "mobx-react-lite"
|
|
110
110
|
|
|
111
111
|
// Model the application state.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
reset() {
|
|
124
|
-
this.secondsPassed = 0
|
|
125
|
-
}
|
|
112
|
+
function createTimer() {
|
|
113
|
+
return makeAutoObservable({
|
|
114
|
+
secondsPassed: 0,
|
|
115
|
+
increase() {
|
|
116
|
+
this.secondsPassed += 1
|
|
117
|
+
},
|
|
118
|
+
reset() {
|
|
119
|
+
this.secondsPassed = 0
|
|
120
|
+
}
|
|
121
|
+
})
|
|
126
122
|
}
|
|
127
123
|
|
|
128
|
-
const myTimer =
|
|
124
|
+
const myTimer = createTimer()
|
|
129
125
|
|
|
130
126
|
// Build a "user interface" that uses the observable state.
|
|
131
127
|
const TimerView = observer(({ timer }) => (
|
package/dist/core/atom.d.ts
CHANGED
|
@@ -37,11 +37,6 @@ export declare class MobXGlobals {
|
|
|
37
37
|
* Are we in a batch block? (and how many of them)
|
|
38
38
|
*/
|
|
39
39
|
inBatch: number;
|
|
40
|
-
/**
|
|
41
|
-
* ID of the latest batch. Used to suppress reportChanged of newly created atoms.
|
|
42
|
-
* Note the value persists even after batch ended.
|
|
43
|
-
*/
|
|
44
|
-
batchId: number;
|
|
45
40
|
/**
|
|
46
41
|
* Observables that don't have observers anymore, and are about to be
|
|
47
42
|
* suspended, unless somebody else accesses it in the same batch
|
|
@@ -106,10 +101,6 @@ export declare class MobXGlobals {
|
|
|
106
101
|
* configurable: true
|
|
107
102
|
*/
|
|
108
103
|
safeDescriptors: boolean;
|
|
109
|
-
/**
|
|
110
|
-
* Changes with each state update, used by useSyncExternalStore
|
|
111
|
-
*/
|
|
112
|
-
stateVersion: number;
|
|
113
104
|
}
|
|
114
105
|
export declare let globalState: MobXGlobals;
|
|
115
106
|
export declare function isolateGlobalState(): void;
|
|
@@ -420,7 +420,7 @@ function is20223Decorator(context) {
|
|
|
420
420
|
}
|
|
421
421
|
function assert20223DecoratorType(context, types) {
|
|
422
422
|
if ( !types.includes(context.kind)) {
|
|
423
|
-
die("
|
|
423
|
+
die("The decorator applied to '" + String(context.name) + "' cannot be used on a " + context.kind + " element");
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
|
|
@@ -440,14 +440,12 @@ var Atom = /*#__PURE__*/function () {
|
|
|
440
440
|
this.isPendingUnobservation_ = false;
|
|
441
441
|
this.isBeingObserved_ = false;
|
|
442
442
|
this.observers_ = new Set();
|
|
443
|
-
this.batchId_ = void 0;
|
|
444
443
|
this.diffValue_ = 0;
|
|
445
444
|
this.lastAccessedBy_ = 0;
|
|
446
445
|
this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
|
|
447
446
|
this.onBOL = void 0;
|
|
448
447
|
this.onBUOL = void 0;
|
|
449
448
|
this.name_ = name_;
|
|
450
|
-
this.batchId_ = globalState.inBatch ? globalState.batchId : NaN;
|
|
451
449
|
}
|
|
452
450
|
// onBecomeObservedListeners
|
|
453
451
|
var _proto = Atom.prototype;
|
|
@@ -476,13 +474,6 @@ var Atom = /*#__PURE__*/function () {
|
|
|
476
474
|
* Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
|
|
477
475
|
*/;
|
|
478
476
|
_proto.reportChanged = function reportChanged() {
|
|
479
|
-
if (!globalState.inBatch || this.batchId_ !== globalState.batchId) {
|
|
480
|
-
// We could update state version only at the end of batch,
|
|
481
|
-
// but we would still have to switch some global flag here to signal a change.
|
|
482
|
-
globalState.stateVersion = globalState.stateVersion < Number.MAX_SAFE_INTEGER ? globalState.stateVersion + 1 : Number.MIN_SAFE_INTEGER;
|
|
483
|
-
// Avoids the possibility of hitting the same globalState.batchId when it cycled through all integers (necessary?)
|
|
484
|
-
this.batchId_ = NaN;
|
|
485
|
-
}
|
|
486
477
|
startBatch();
|
|
487
478
|
propagateChanged(this);
|
|
488
479
|
endBatch();
|
|
@@ -918,24 +909,21 @@ function extend_$4(adm, key, descriptor, proxyTrap) {
|
|
|
918
909
|
}
|
|
919
910
|
function decorate_20223_$4(desc, context) {
|
|
920
911
|
{
|
|
921
|
-
|
|
912
|
+
if (context.kind === "field") {
|
|
913
|
+
throw die("Please use `@observable accessor " + String(context.name) + "` instead of `@observable " + String(context.name) + "`");
|
|
914
|
+
}
|
|
915
|
+
assert20223DecoratorType(context, ["accessor"]);
|
|
922
916
|
}
|
|
923
917
|
var ann = this;
|
|
924
918
|
var kind = context.kind,
|
|
925
|
-
name = context.name
|
|
926
|
-
addInitializer = context.addInitializer;
|
|
927
|
-
// Backwards/Legacy behavior, expects makeObservable(this)
|
|
928
|
-
if (kind == "field") {
|
|
929
|
-
addInitializer(function () {
|
|
930
|
-
storeAnnotation(this, name, ann);
|
|
931
|
-
});
|
|
932
|
-
return;
|
|
933
|
-
}
|
|
919
|
+
name = context.name;
|
|
934
920
|
// The laziness here is not ideal... It's a workaround to how 2022.3 Decorators are implemented:
|
|
935
921
|
// `addInitializer` callbacks are executed _before_ any accessors are defined (instead of the ideal-for-us right after each).
|
|
936
922
|
// This means that, if we were to do our stuff in an `addInitializer`, we'd attempt to read a private slot
|
|
937
923
|
// before it has been initialized. The runtime doesn't like that and throws a `Cannot read private member
|
|
938
924
|
// from an object whose class did not declare it` error.
|
|
925
|
+
// TODO: it seems that this will not be required anymore in the final version of the spec
|
|
926
|
+
// See TODO: link
|
|
939
927
|
var initializedObjects = new WeakSet();
|
|
940
928
|
function initializeObservable(target, value) {
|
|
941
929
|
var _ann$options_$enhance, _ann$options_;
|
|
@@ -1238,6 +1226,9 @@ function createAction(actionName, fn, autoAction, ref) {
|
|
|
1238
1226
|
return executeAction(actionName, autoAction, fn, ref || this, arguments);
|
|
1239
1227
|
}
|
|
1240
1228
|
res.isMobxAction = true;
|
|
1229
|
+
res.toString = function () {
|
|
1230
|
+
return fn.toString();
|
|
1231
|
+
};
|
|
1241
1232
|
if (isFunctionNameConfigurable) {
|
|
1242
1233
|
tmpNameDescriptor.value = actionName;
|
|
1243
1234
|
defineProperty(res, "name", tmpNameDescriptor);
|
|
@@ -1985,7 +1976,6 @@ var MobXGlobals = function MobXGlobals() {
|
|
|
1985
1976
|
this.runId = 0;
|
|
1986
1977
|
this.mobxGuid = 0;
|
|
1987
1978
|
this.inBatch = 0;
|
|
1988
|
-
this.batchId = Number.MIN_SAFE_INTEGER;
|
|
1989
1979
|
this.pendingUnobservations = [];
|
|
1990
1980
|
this.pendingReactions = [];
|
|
1991
1981
|
this.isRunningReactions = false;
|
|
@@ -2002,7 +1992,6 @@ var MobXGlobals = function MobXGlobals() {
|
|
|
2002
1992
|
this.useProxies = true;
|
|
2003
1993
|
this.verifyProxies = false;
|
|
2004
1994
|
this.safeDescriptors = true;
|
|
2005
|
-
this.stateVersion = Number.MIN_SAFE_INTEGER;
|
|
2006
1995
|
};
|
|
2007
1996
|
var canMergeGlobalState = true;
|
|
2008
1997
|
var isolateCalled = false;
|
|
@@ -2125,9 +2114,6 @@ function queueForUnobservation(observable) {
|
|
|
2125
2114
|
* Avoids unnecessary recalculations.
|
|
2126
2115
|
*/
|
|
2127
2116
|
function startBatch() {
|
|
2128
|
-
if (globalState.inBatch === 0) {
|
|
2129
|
-
globalState.batchId = globalState.batchId < Number.MAX_SAFE_INTEGER ? globalState.batchId + 1 : Number.MIN_SAFE_INTEGER;
|
|
2130
|
-
}
|
|
2131
2117
|
globalState.inBatch++;
|
|
2132
2118
|
}
|
|
2133
2119
|
function endBatch() {
|
|
@@ -3964,6 +3950,7 @@ var arrayExtensions = {
|
|
|
3964
3950
|
* Without this, everything works as well, but this works
|
|
3965
3951
|
* faster as everything works on unproxied values
|
|
3966
3952
|
*/
|
|
3953
|
+
addArrayExtension("at", simpleFunc);
|
|
3967
3954
|
addArrayExtension("concat", simpleFunc);
|
|
3968
3955
|
addArrayExtension("flat", simpleFunc);
|
|
3969
3956
|
addArrayExtension("includes", simpleFunc);
|
|
@@ -3973,15 +3960,21 @@ addArrayExtension("lastIndexOf", simpleFunc);
|
|
|
3973
3960
|
addArrayExtension("slice", simpleFunc);
|
|
3974
3961
|
addArrayExtension("toString", simpleFunc);
|
|
3975
3962
|
addArrayExtension("toLocaleString", simpleFunc);
|
|
3963
|
+
addArrayExtension("toSorted", simpleFunc);
|
|
3964
|
+
addArrayExtension("toSpliced", simpleFunc);
|
|
3965
|
+
addArrayExtension("with", simpleFunc);
|
|
3976
3966
|
// map
|
|
3977
3967
|
addArrayExtension("every", mapLikeFunc);
|
|
3978
3968
|
addArrayExtension("filter", mapLikeFunc);
|
|
3979
3969
|
addArrayExtension("find", mapLikeFunc);
|
|
3980
3970
|
addArrayExtension("findIndex", mapLikeFunc);
|
|
3971
|
+
addArrayExtension("findLast", mapLikeFunc);
|
|
3972
|
+
addArrayExtension("findLastIndex", mapLikeFunc);
|
|
3981
3973
|
addArrayExtension("flatMap", mapLikeFunc);
|
|
3982
3974
|
addArrayExtension("forEach", mapLikeFunc);
|
|
3983
3975
|
addArrayExtension("map", mapLikeFunc);
|
|
3984
3976
|
addArrayExtension("some", mapLikeFunc);
|
|
3977
|
+
addArrayExtension("toReversed", mapLikeFunc);
|
|
3985
3978
|
// reduce
|
|
3986
3979
|
addArrayExtension("reduce", reduceLikeFunc);
|
|
3987
3980
|
addArrayExtension("reduceRight", reduceLikeFunc);
|