mobx 6.16.1 → 7.0.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 +72 -0
- package/README.md +9 -13
- package/dist/api/action.d.ts +6 -4
- package/dist/api/annotation.d.ts +0 -1
- package/dist/api/computed.d.ts +4 -7
- package/dist/api/configure.d.ts +0 -1
- package/dist/api/decoratorannotation.d.ts +3 -0
- package/dist/api/decorators.d.ts +0 -19
- package/dist/api/flow.d.ts +4 -5
- package/dist/api/makeObservable.d.ts +2 -3
- package/dist/api/observable.d.ts +9 -15
- package/dist/core/atom.d.ts +0 -3
- package/dist/core/computedvalue.d.ts +4 -32
- package/dist/core/derivation.d.ts +1 -7
- package/dist/core/globalstate.d.ts +0 -2
- package/dist/core/reaction.d.ts +1 -9
- package/dist/errors.d.ts +6 -4
- package/dist/internal.d.ts +1 -4
- package/dist/mobx.cjs.development.js +1630 -2447
- 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.d.ts +2 -2
- package/dist/mobx.esm.development.js +1619 -2446
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +1567 -2397
- 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 +5271 -0
- package/dist/mobx.mjs.map +1 -0
- package/dist/mobx.umd.development.js +1633 -2450
- 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/actionannotation.d.ts +1 -0
- package/dist/types/computedannotation.d.ts +1 -0
- package/dist/types/decorator_fills.d.ts +2 -0
- package/dist/types/flowannotation.d.ts +1 -0
- package/dist/types/observableannotation.d.ts +5 -0
- package/dist/types/observablearray.d.ts +2 -5
- package/dist/types/observablemap.d.ts +1 -8
- package/dist/types/observableobject.d.ts +2 -13
- package/dist/types/observableset.d.ts +1 -3
- package/dist/types/observablevalue.d.ts +4 -6
- package/dist/types/overrideannotation.d.ts +1 -2
- package/dist/utils/comparer.d.ts +4 -11
- package/dist/utils/utils.d.ts +0 -2
- package/package.json +25 -15
- package/src/api/action.ts +27 -35
- package/src/api/annotation.ts +0 -1
- package/src/api/autorun.ts +2 -4
- package/src/api/computed.ts +21 -28
- package/src/api/configure.ts +1 -15
- package/src/api/decoratorannotation.ts +20 -0
- package/src/api/decorators.ts +1 -85
- package/src/api/extras.ts +1 -1
- package/src/api/flow.ts +26 -29
- package/src/api/intercept.ts +4 -3
- package/src/api/makeObservable.ts +45 -17
- package/src/api/object-api.ts +1 -1
- package/src/api/observable.ts +34 -67
- package/src/api/observe.ts +82 -3
- package/src/api/when.ts +4 -3
- package/src/core/action.ts +12 -5
- package/src/core/atom.ts +14 -13
- package/src/core/computedvalue.ts +27 -67
- package/src/core/derivation.ts +15 -14
- package/src/core/globalstate.ts +8 -13
- package/src/core/observable.ts +0 -48
- package/src/core/reaction.ts +19 -25
- package/src/core/spy.ts +3 -3
- package/src/errors.ts +23 -12
- package/src/internal.ts +1 -4
- package/src/mobx.ts +21 -10
- package/src/types/actionannotation.ts +5 -9
- package/src/types/autoannotation.ts +8 -11
- package/src/types/computedannotation.ts +13 -11
- package/src/types/decorator_fills.ts +4 -0
- package/src/types/dynamicobject.ts +0 -29
- package/src/types/flowannotation.ts +7 -4
- package/src/types/observableannotation.ts +6 -7
- package/src/types/observablearray.ts +8 -61
- package/src/types/observablemap.ts +4 -29
- package/src/types/observableobject.ts +5 -70
- package/src/types/observableset.ts +5 -28
- package/src/types/observablevalue.ts +7 -29
- package/src/types/overrideannotation.ts +7 -22
- package/src/types/type-utils.ts +4 -2
- package/src/utils/comparer.ts +4 -17
- package/src/utils/iterable.ts +3 -4
- package/src/utils/utils.ts +4 -46
- package/dist/api/trace.d.ts +0 -3
- package/dist/types/legacyobservablearray.d.ts +0 -14
- package/dist/utils/global.d.ts +0 -1
- package/src/api/trace.ts +0 -35
- package/src/types/legacyobservablearray.ts +0 -155
- package/src/utils/global.ts +0 -20
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getNextId,
|
|
3
|
-
addHiddenFinalProp,
|
|
4
|
-
makeIterable,
|
|
5
|
-
addHiddenProp,
|
|
6
|
-
ObservableArrayAdministration,
|
|
7
|
-
$mobx,
|
|
8
|
-
arrayExtensions,
|
|
9
|
-
IEnhancer,
|
|
10
|
-
isObservableArray,
|
|
11
|
-
IObservableArray,
|
|
12
|
-
defineProperty,
|
|
13
|
-
initObservable
|
|
14
|
-
} from "../internal"
|
|
15
|
-
|
|
16
|
-
// Bug in safari 9.* (or iOS 9 safari mobile). See #364
|
|
17
|
-
const ENTRY_0 = createArrayEntryDescriptor(0)
|
|
18
|
-
|
|
19
|
-
const safariPrototypeSetterInheritanceBug = (() => {
|
|
20
|
-
let v = false
|
|
21
|
-
const p = {}
|
|
22
|
-
Object.defineProperty(p, "0", {
|
|
23
|
-
set: () => {
|
|
24
|
-
v = true
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
Object.create(p)["0"] = 1
|
|
28
|
-
return v === false
|
|
29
|
-
})()
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* This array buffer contains two lists of properties, so that all arrays
|
|
33
|
-
* can recycle their property definitions, which significantly improves performance of creating
|
|
34
|
-
* properties on the fly.
|
|
35
|
-
*/
|
|
36
|
-
let OBSERVABLE_ARRAY_BUFFER_SIZE = 0
|
|
37
|
-
|
|
38
|
-
// Typescript workaround to make sure ObservableArray extends Array
|
|
39
|
-
class StubArray {}
|
|
40
|
-
function inherit(ctor, proto) {
|
|
41
|
-
if (Object.setPrototypeOf) {
|
|
42
|
-
Object.setPrototypeOf(ctor.prototype, proto)
|
|
43
|
-
} else if (ctor.prototype.__proto__ !== undefined) {
|
|
44
|
-
ctor.prototype.__proto__ = proto
|
|
45
|
-
} else {
|
|
46
|
-
ctor.prototype = proto
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
inherit(StubArray, Array.prototype)
|
|
50
|
-
|
|
51
|
-
// Weex proto freeze protection was here,
|
|
52
|
-
// but it is unclear why the hack is need as MobX never changed the prototype
|
|
53
|
-
// anyway, so removed it in V6
|
|
54
|
-
|
|
55
|
-
export class LegacyObservableArray<T> extends StubArray {
|
|
56
|
-
constructor(
|
|
57
|
-
initialValues: T[] | undefined,
|
|
58
|
-
enhancer: IEnhancer<T>,
|
|
59
|
-
name = __DEV__ ? "ObservableArray@" + getNextId() : "ObservableArray",
|
|
60
|
-
owned = false
|
|
61
|
-
) {
|
|
62
|
-
super()
|
|
63
|
-
initObservable(() => {
|
|
64
|
-
const adm = new ObservableArrayAdministration(name, enhancer, owned, true)
|
|
65
|
-
adm.proxy_ = this as any
|
|
66
|
-
addHiddenFinalProp(this, $mobx, adm)
|
|
67
|
-
|
|
68
|
-
if (initialValues && initialValues.length) {
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
this.spliceWithArray(0, 0, initialValues)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (safariPrototypeSetterInheritanceBug) {
|
|
74
|
-
// Seems that Safari won't use numeric prototype setter until any * numeric property is
|
|
75
|
-
// defined on the instance. After that it works fine, even if this property is deleted.
|
|
76
|
-
Object.defineProperty(this, "0", ENTRY_0)
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
concat(...arrays: T[][]): T[] {
|
|
82
|
-
;(this[$mobx] as ObservableArrayAdministration).atom_.reportObserved()
|
|
83
|
-
return Array.prototype.concat.apply(
|
|
84
|
-
(this as any).slice(),
|
|
85
|
-
//@ts-ignore
|
|
86
|
-
arrays.map(a => (isObservableArray(a) ? a.slice() : a))
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
get length(): number {
|
|
91
|
-
return (this[$mobx] as ObservableArrayAdministration).getArrayLength_()
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
set length(newLength: number) {
|
|
95
|
-
;(this[$mobx] as ObservableArrayAdministration).setArrayLength_(newLength)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get [Symbol.toStringTag]() {
|
|
99
|
-
return "Array"
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
[Symbol.iterator]() {
|
|
103
|
-
const self = this
|
|
104
|
-
let nextIndex = 0
|
|
105
|
-
return makeIterable({
|
|
106
|
-
next() {
|
|
107
|
-
return nextIndex < self.length
|
|
108
|
-
? { value: self[nextIndex++], done: false }
|
|
109
|
-
: { done: true, value: undefined }
|
|
110
|
-
}
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
Object.entries(arrayExtensions).forEach(([prop, fn]) => {
|
|
116
|
-
if (prop !== "concat") {
|
|
117
|
-
addHiddenProp(LegacyObservableArray.prototype, prop, fn)
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
function createArrayEntryDescriptor(index: number) {
|
|
122
|
-
return {
|
|
123
|
-
enumerable: false,
|
|
124
|
-
configurable: true,
|
|
125
|
-
get: function () {
|
|
126
|
-
return this[$mobx].get_(index)
|
|
127
|
-
},
|
|
128
|
-
set: function (value) {
|
|
129
|
-
this[$mobx].set_(index, value)
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function createArrayBufferItem(index: number) {
|
|
135
|
-
defineProperty(LegacyObservableArray.prototype, "" + index, createArrayEntryDescriptor(index))
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function reserveArrayBuffer(max: number) {
|
|
139
|
-
if (max > OBSERVABLE_ARRAY_BUFFER_SIZE) {
|
|
140
|
-
for (let index = OBSERVABLE_ARRAY_BUFFER_SIZE; index < max + 100; index++) {
|
|
141
|
-
createArrayBufferItem(index)
|
|
142
|
-
}
|
|
143
|
-
OBSERVABLE_ARRAY_BUFFER_SIZE = max
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
reserveArrayBuffer(1000)
|
|
148
|
-
|
|
149
|
-
export function createLegacyArray<T>(
|
|
150
|
-
initialValues: T[] | undefined,
|
|
151
|
-
enhancer: IEnhancer<T>,
|
|
152
|
-
name?: string
|
|
153
|
-
): IObservableArray<T> {
|
|
154
|
-
return new LegacyObservableArray(initialValues, enhancer, name) as any
|
|
155
|
-
}
|
package/src/utils/global.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
declare const window: any
|
|
2
|
-
declare const self: any
|
|
3
|
-
|
|
4
|
-
const mockGlobal = {}
|
|
5
|
-
|
|
6
|
-
export function getGlobal() {
|
|
7
|
-
if (typeof globalThis !== "undefined") {
|
|
8
|
-
return globalThis
|
|
9
|
-
}
|
|
10
|
-
if (typeof window !== "undefined") {
|
|
11
|
-
return window
|
|
12
|
-
}
|
|
13
|
-
if (typeof global !== "undefined") {
|
|
14
|
-
return global
|
|
15
|
-
}
|
|
16
|
-
if (typeof self !== "undefined") {
|
|
17
|
-
return self
|
|
18
|
-
}
|
|
19
|
-
return mockGlobal
|
|
20
|
-
}
|