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
|
@@ -94,6 +94,5 @@ export interface IIsObservableObject {
|
|
|
94
94
|
$mobx: ObservableObjectAdministration;
|
|
95
95
|
}
|
|
96
96
|
export declare function asObservableObject(target: any, options?: CreateObservableOptions): IIsObservableObject;
|
|
97
|
-
export declare function getCachedFallthroughPropDescriptor(key: any): any;
|
|
98
97
|
export declare function isObservableObject(thing: any): boolean;
|
|
99
98
|
export declare function recordAnnotationApplied(adm: ObservableObjectAdministration, annotation: Annotation, key: PropertyKey): void;
|
package/package.json
CHANGED
package/src/api/decorators.ts
CHANGED
|
@@ -89,6 +89,10 @@ export function assert20223DecoratorType(
|
|
|
89
89
|
types: DecoratorContext["kind"][]
|
|
90
90
|
) {
|
|
91
91
|
if (__DEV__ && !types.includes(context.kind)) {
|
|
92
|
-
die(
|
|
92
|
+
die(
|
|
93
|
+
`The decorator applied to '${String(context.name)}' cannot be used on a ${
|
|
94
|
+
context.kind
|
|
95
|
+
} element`
|
|
96
|
+
)
|
|
93
97
|
}
|
|
94
98
|
}
|
package/src/api/observable.ts
CHANGED
|
@@ -156,6 +156,7 @@ export interface IObservableFactory
|
|
|
156
156
|
PropertyDecorator,
|
|
157
157
|
ClassAccessorDecorator,
|
|
158
158
|
ClassFieldDecorator {
|
|
159
|
+
// TODO: remove ClassFieldDecorator, this is only temporarily support for legacy decorators
|
|
159
160
|
<T = any>(value: T[], options?: CreateObservableOptions): IObservableArray<T>
|
|
160
161
|
<T = any>(value: Set<T>, options?: CreateObservableOptions): ObservableSet<T>
|
|
161
162
|
<K = any, V = any>(value: Map<K, V>, options?: CreateObservableOptions): ObservableMap<K, V>
|
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/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
|
|
|
@@ -7,8 +7,7 @@ import {
|
|
|
7
7
|
assert20223DecoratorType,
|
|
8
8
|
ObservableValue,
|
|
9
9
|
asObservableObject,
|
|
10
|
-
$mobx
|
|
11
|
-
storeAnnotation
|
|
10
|
+
$mobx
|
|
12
11
|
} from "../internal"
|
|
13
12
|
|
|
14
13
|
export function createObservableAnnotation(name: string, options?: object): Annotation {
|
|
@@ -52,25 +51,26 @@ function decorate_20223_(
|
|
|
52
51
|
context: ClassAccessorDecoratorContext | ClassFieldDecoratorContext
|
|
53
52
|
) {
|
|
54
53
|
if (__DEV__) {
|
|
55
|
-
|
|
54
|
+
if (context.kind === "field") {
|
|
55
|
+
throw die(
|
|
56
|
+
`Please use \`@observable accessor ${String(
|
|
57
|
+
context.name
|
|
58
|
+
)}\` instead of \`@observable ${String(context.name)}\``
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
assert20223DecoratorType(context, ["accessor"])
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
const ann = this
|
|
59
|
-
const { kind, name
|
|
60
|
-
|
|
61
|
-
// Backwards/Legacy behavior, expects makeObservable(this)
|
|
62
|
-
if (kind == "field") {
|
|
63
|
-
addInitializer(function () {
|
|
64
|
-
storeAnnotation(this, name, ann)
|
|
65
|
-
})
|
|
66
|
-
return
|
|
67
|
-
}
|
|
65
|
+
const { kind, name } = context
|
|
68
66
|
|
|
69
67
|
// The laziness here is not ideal... It's a workaround to how 2022.3 Decorators are implemented:
|
|
70
68
|
// `addInitializer` callbacks are executed _before_ any accessors are defined (instead of the ideal-for-us right after each).
|
|
71
69
|
// This means that, if we were to do our stuff in an `addInitializer`, we'd attempt to read a private slot
|
|
72
70
|
// before it has been initialized. The runtime doesn't like that and throws a `Cannot read private member
|
|
73
71
|
// from an object whose class did not declare it` error.
|
|
72
|
+
// TODO: it seems that this will not be required anymore in the final version of the spec
|
|
73
|
+
// See TODO: link
|
|
74
74
|
const initializedObjects = new WeakSet()
|
|
75
75
|
|
|
76
76
|
function initializeObservable(target, value) {
|
|
@@ -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)
|
|
@@ -712,22 +712,6 @@ function getCachedObservablePropDescriptor(key) {
|
|
|
712
712
|
)
|
|
713
713
|
}
|
|
714
714
|
|
|
715
|
-
const fallthroughDescriptorCache = Object.create(null)
|
|
716
|
-
|
|
717
|
-
export function getCachedFallthroughPropDescriptor(key) {
|
|
718
|
-
return (
|
|
719
|
-
fallthroughDescriptorCache[key] ||
|
|
720
|
-
(fallthroughDescriptorCache[key] = {
|
|
721
|
-
get() {
|
|
722
|
-
return Reflect.get(Object.getPrototypeOf(this), key, this)
|
|
723
|
-
},
|
|
724
|
-
set(v) {
|
|
725
|
-
return Reflect.set(Object.getPrototypeOf(this), key, v, this)
|
|
726
|
-
}
|
|
727
|
-
})
|
|
728
|
-
)
|
|
729
|
-
}
|
|
730
|
-
|
|
731
715
|
export function isObservableObject(thing: any): boolean {
|
|
732
716
|
if (isObject(thing)) {
|
|
733
717
|
return isObservableObjectAdministration((thing as any)[$mobx])
|