mobx-react 9.2.1 → 10.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 +79 -0
- package/README.md +8 -264
- package/dist/index.d.ts +1 -6
- package/dist/mobxreact.cjs.development.js +101 -449
- package/dist/mobxreact.cjs.development.js.map +1 -1
- package/dist/mobxreact.cjs.production.min.js +1 -1
- package/dist/mobxreact.cjs.production.min.js.map +1 -1
- package/dist/mobxreact.esm.development.js +76 -405
- package/dist/mobxreact.esm.development.js.map +1 -1
- package/dist/mobxreact.esm.js +75 -404
- package/dist/mobxreact.esm.js.map +1 -1
- package/dist/mobxreact.esm.production.min.js +1 -1
- package/dist/mobxreact.esm.production.min.js.map +1 -1
- package/dist/mobxreact.mjs +338 -0
- package/dist/mobxreact.mjs.map +1 -0
- package/dist/mobxreact.umd.development.js +103 -450
- package/dist/mobxreact.umd.development.js.map +1 -1
- package/dist/mobxreact.umd.production.min.js +1 -1
- package/dist/mobxreact.umd.production.min.js.map +1 -1
- package/dist/utils/utils.d.ts +0 -8
- package/package.json +32 -22
- package/src/index.ts +3 -12
- package/src/observer.tsx +9 -8
- package/src/utils/utils.ts +0 -46
- package/batchingForReactDom.js +0 -1
- package/batchingForReactNative.js +0 -1
- package/batchingOptOut.js +0 -1
- package/dist/Provider.d.ts +0 -10
- package/dist/disposeOnUnmount.d.ts +0 -11
- package/dist/inject.d.ts +0 -6
- package/dist/propTypes.d.ts +0 -9
- package/dist/types/IStoresToProps.d.ts +0 -2
- package/dist/types/IValueMap.d.ts +0 -1
- package/dist/types/IWrappedComponent.d.ts +0 -4
- package/src/Provider.tsx +0 -29
- package/src/disposeOnUnmount.ts +0 -111
- package/src/inject.ts +0 -107
- package/src/propTypes.ts +0 -210
- package/src/types/IStoresToProps.ts +0 -7
- package/src/types/IValueMap.ts +0 -1
- package/src/types/IWrappedComponent.ts +0 -4
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('mobx'), require('react'), require('mobx-react-lite')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'mobx', 'react', 'mobx-react-lite'], factory) :
|
|
4
|
-
(global = global || self, factory(global.mobxReact = {}, global.mobx, global.React, global.mobxReactLite));
|
|
5
|
-
}(this, (function (exports, mobx, React, mobxReactLite) { 'use strict';
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.mobxReact = {}, global.mobx, global.React, global.mobxReactLite));
|
|
5
|
+
})(this, (function (exports, mobx, React, mobxReactLite) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n["default"] = e;
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
8
26
|
|
|
9
27
|
function shallowEqual(objA, objB) {
|
|
10
28
|
//From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js
|
|
@@ -14,12 +32,12 @@
|
|
|
14
32
|
if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
|
|
15
33
|
return false;
|
|
16
34
|
}
|
|
17
|
-
|
|
18
|
-
|
|
35
|
+
const keysA = Object.keys(objA);
|
|
36
|
+
const keysB = Object.keys(objB);
|
|
19
37
|
if (keysA.length !== keysB.length) {
|
|
20
38
|
return false;
|
|
21
39
|
}
|
|
22
|
-
for (
|
|
40
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
23
41
|
if (!Object.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
|
|
24
42
|
return false;
|
|
25
43
|
}
|
|
@@ -34,53 +52,24 @@
|
|
|
34
52
|
return x !== x && y !== y;
|
|
35
53
|
}
|
|
36
54
|
}
|
|
37
|
-
// based on https://github.com/mridgway/hoist-non-react-statics/blob/master/src/index.js
|
|
38
|
-
var hoistBlackList = {
|
|
39
|
-
$$typeof: 1,
|
|
40
|
-
render: 1,
|
|
41
|
-
compare: 1,
|
|
42
|
-
type: 1,
|
|
43
|
-
childContextTypes: 1,
|
|
44
|
-
contextType: 1,
|
|
45
|
-
contextTypes: 1,
|
|
46
|
-
defaultProps: 1,
|
|
47
|
-
getDefaultProps: 1,
|
|
48
|
-
getDerivedStateFromError: 1,
|
|
49
|
-
getDerivedStateFromProps: 1,
|
|
50
|
-
mixins: 1,
|
|
51
|
-
displayName: 1,
|
|
52
|
-
propTypes: 1
|
|
53
|
-
};
|
|
54
|
-
function copyStaticProperties(base, target) {
|
|
55
|
-
var protoProps = Object.getOwnPropertyNames(Object.getPrototypeOf(base));
|
|
56
|
-
Object.getOwnPropertyNames(base).forEach(function (key) {
|
|
57
|
-
if (!hoistBlackList[key] && protoProps.indexOf(key) === -1) {
|
|
58
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(base, key));
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
55
|
/**
|
|
63
56
|
* Utilities for patching componentWillUnmount, to make sure @disposeOnUnmount works correctly icm with user defined hooks
|
|
64
57
|
* and the handler provided by mobx-react
|
|
65
58
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
const mobxMixins = /*#__PURE__*/Symbol("patchMixins");
|
|
60
|
+
const mobxPatchedDefinition = /*#__PURE__*/Symbol("patchedDefinition");
|
|
68
61
|
function getMixins(target, methodName) {
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
const mixins = target[mobxMixins] = target[mobxMixins] || {};
|
|
63
|
+
const methodMixins = mixins[methodName] = mixins[methodName] || {};
|
|
71
64
|
methodMixins.locks = methodMixins.locks || 0;
|
|
72
65
|
methodMixins.methods = methodMixins.methods || [];
|
|
73
66
|
return methodMixins;
|
|
74
67
|
}
|
|
75
|
-
function wrapper(realMethod, mixins) {
|
|
76
|
-
var _this = this;
|
|
77
|
-
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
78
|
-
args[_key - 2] = arguments[_key];
|
|
79
|
-
}
|
|
68
|
+
function wrapper(realMethod, mixins, ...args) {
|
|
80
69
|
// locks are used to ensure that mixins are invoked only once per invocation, even on recursive calls
|
|
81
70
|
mixins.locks++;
|
|
82
71
|
try {
|
|
83
|
-
|
|
72
|
+
let retVal;
|
|
84
73
|
if (realMethod !== undefined && realMethod !== null) {
|
|
85
74
|
retVal = realMethod.apply(this, args);
|
|
86
75
|
}
|
|
@@ -88,57 +77,60 @@
|
|
|
88
77
|
} finally {
|
|
89
78
|
mixins.locks--;
|
|
90
79
|
if (mixins.locks === 0) {
|
|
91
|
-
mixins.methods.forEach(
|
|
92
|
-
mx.apply(
|
|
80
|
+
mixins.methods.forEach(mx => {
|
|
81
|
+
mx.apply(this, args);
|
|
93
82
|
});
|
|
94
83
|
}
|
|
95
84
|
}
|
|
96
85
|
}
|
|
97
86
|
function wrapFunction(realMethod, mixins) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
args[_key2] = arguments[_key2];
|
|
101
|
-
}
|
|
102
|
-
wrapper.call.apply(wrapper, [this, realMethod, mixins].concat(args));
|
|
87
|
+
const fn = function fn(...args) {
|
|
88
|
+
wrapper.call(this, realMethod, mixins, ...args);
|
|
103
89
|
};
|
|
104
90
|
return fn;
|
|
105
91
|
}
|
|
106
92
|
function patch(target, methodName, mixinMethod) {
|
|
107
|
-
|
|
93
|
+
const mixins = getMixins(target, methodName);
|
|
108
94
|
if (mixins.methods.indexOf(mixinMethod) < 0) {
|
|
109
95
|
mixins.methods.push(mixinMethod);
|
|
110
96
|
}
|
|
111
|
-
|
|
97
|
+
const oldDefinition = Object.getOwnPropertyDescriptor(target, methodName);
|
|
112
98
|
if (oldDefinition && oldDefinition[mobxPatchedDefinition]) {
|
|
113
99
|
// already patched definition, do not repatch
|
|
114
100
|
return;
|
|
115
101
|
}
|
|
116
|
-
|
|
117
|
-
|
|
102
|
+
const originalMethod = target[methodName];
|
|
103
|
+
const newDefinition = createDefinition(target, methodName, oldDefinition ? oldDefinition.enumerable : undefined, mixins, originalMethod);
|
|
118
104
|
Object.defineProperty(target, methodName, newDefinition);
|
|
119
105
|
}
|
|
120
106
|
function createDefinition(target, methodName, enumerable, mixins, originalMethod) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
107
|
+
let wrappedFunc = wrapFunction(originalMethod, mixins);
|
|
108
|
+
return {
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
[mobxPatchedDefinition]: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return wrappedFunc;
|
|
113
|
+
},
|
|
114
|
+
set: function (value) {
|
|
115
|
+
if (this === target) {
|
|
116
|
+
wrappedFunc = wrapFunction(value, mixins);
|
|
117
|
+
} else {
|
|
118
|
+
// when it is an instance of the prototype/a child prototype patch that particular case again separately
|
|
119
|
+
// since we need to store separate values depending on wether it is the actual instance, the prototype, etc
|
|
120
|
+
// e.g. the method for super might not be the same as the method for the prototype which might be not the same
|
|
121
|
+
// as the method for the instance
|
|
122
|
+
const newDefinition = createDefinition(this, methodName, enumerable, mixins, value);
|
|
123
|
+
Object.defineProperty(this, methodName, newDefinition);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
configurable: true,
|
|
127
|
+
enumerable: enumerable
|
|
128
|
+
};
|
|
137
129
|
}
|
|
138
130
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
131
|
+
const administrationSymbol = /*#__PURE__*/Symbol("ObserverAdministration");
|
|
132
|
+
const isMobXReactObserverSymbol = /*#__PURE__*/Symbol("isMobXReactObserver");
|
|
133
|
+
let observablePropDescriptors;
|
|
142
134
|
{
|
|
143
135
|
observablePropDescriptors = {
|
|
144
136
|
props: /*#__PURE__*/createObservablePropDescriptor("props"),
|
|
@@ -163,10 +155,12 @@
|
|
|
163
155
|
};
|
|
164
156
|
}
|
|
165
157
|
function makeClassComponentObserver(componentClass) {
|
|
166
|
-
|
|
158
|
+
const {
|
|
159
|
+
prototype
|
|
160
|
+
} = componentClass;
|
|
167
161
|
if (componentClass[isMobXReactObserverSymbol]) {
|
|
168
|
-
|
|
169
|
-
throw new Error(
|
|
162
|
+
const displayName = getDisplayName(componentClass);
|
|
163
|
+
throw new Error(`The provided component class (${displayName}) has already been declared as an observer component.`);
|
|
170
164
|
} else {
|
|
171
165
|
componentClass[isMobXReactObserverSymbol] = true;
|
|
172
166
|
}
|
|
@@ -184,10 +178,10 @@
|
|
|
184
178
|
{
|
|
185
179
|
Object.defineProperties(prototype, observablePropDescriptors);
|
|
186
180
|
}
|
|
187
|
-
|
|
181
|
+
const originalRender = prototype.render;
|
|
188
182
|
if (typeof originalRender !== "function") {
|
|
189
|
-
|
|
190
|
-
throw new Error(
|
|
183
|
+
const displayName = getDisplayName(componentClass);
|
|
184
|
+
throw new Error(`[mobx-react] class component (${displayName}) is missing \`render\` method.` + `\n\`observer\` requires \`render\` being a function defined on prototype.` + `\n\`render = () => {}\` or \`render = function() {}\` is not supported.`);
|
|
191
185
|
}
|
|
192
186
|
prototype.render = function () {
|
|
193
187
|
Object.defineProperty(this, "render", {
|
|
@@ -198,12 +192,11 @@
|
|
|
198
192
|
});
|
|
199
193
|
return this.render();
|
|
200
194
|
};
|
|
201
|
-
|
|
195
|
+
const originalComponentDidMount = prototype.componentDidMount;
|
|
202
196
|
prototype.componentDidMount = function () {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
throw new Error("[mobx-react] `observer(" + _displayName2 + ").componentDidMount` must be defined on prototype." + "\n`componentDidMount = () => {}` or `componentDidMount = function() {}` is not supported.");
|
|
197
|
+
if (this.componentDidMount !== Object.getPrototypeOf(this).componentDidMount) {
|
|
198
|
+
const displayName = getDisplayName(componentClass);
|
|
199
|
+
throw new Error(`[mobx-react] \`observer(${displayName}).componentDidMount\` must be defined on prototype.` + `\n\`componentDidMount = () => {}\` or \`componentDidMount = function() {}\` is not supported.`);
|
|
207
200
|
}
|
|
208
201
|
// `componentDidMount` may not be called at all. React can abandon the instance after `render`.
|
|
209
202
|
// That's why we use finalization registry to dispose reaction created during render.
|
|
@@ -216,7 +209,7 @@
|
|
|
216
209
|
// Therefore we don't have to worry about external (observable) state being updated before mount (no state version checking).
|
|
217
210
|
//
|
|
218
211
|
// Things may change: "In the future, React will provide a feature that lets components preserve state between unmounts"
|
|
219
|
-
|
|
212
|
+
const admin = getAdministration(this);
|
|
220
213
|
admin.mounted = true;
|
|
221
214
|
// Component instance committed, prevent reaction disposal.
|
|
222
215
|
mobxReactLite._observerFinalizationRegistry.unregister(this);
|
|
@@ -224,9 +217,7 @@
|
|
|
224
217
|
// therefore `this` could NOT be garbage collected before mount,
|
|
225
218
|
// preventing reaction disposal by FinalizationRegistry and leading to memory leak.
|
|
226
219
|
// As an alternative we could have `admin.instanceRef = new WeakRef(this)`, but lets avoid it if possible.
|
|
227
|
-
admin.forceUpdate =
|
|
228
|
-
return _this.forceUpdate();
|
|
229
|
-
};
|
|
220
|
+
admin.forceUpdate = () => this.forceUpdate();
|
|
230
221
|
if (!admin.reaction || admin.reactionInvalidatedBeforeMount) {
|
|
231
222
|
// Missing reaction:
|
|
232
223
|
// 1. Instance was unmounted (reaction disposed) and immediately remounted without running render #3395.
|
|
@@ -246,7 +237,7 @@
|
|
|
246
237
|
if (mobxReactLite.isUsingStaticRendering()) {
|
|
247
238
|
return;
|
|
248
239
|
}
|
|
249
|
-
|
|
240
|
+
const admin = getAdministration(this);
|
|
250
241
|
(_admin$reaction = admin.reaction) == null || _admin$reaction.dispose();
|
|
251
242
|
admin.reaction = null;
|
|
252
243
|
admin.forceUpdate = null;
|
|
@@ -260,8 +251,8 @@
|
|
|
260
251
|
return componentClass.displayName || componentClass.name || "<component>";
|
|
261
252
|
}
|
|
262
253
|
function createReactiveRender(originalRender) {
|
|
263
|
-
|
|
264
|
-
|
|
254
|
+
const boundOriginalRender = originalRender.bind(this);
|
|
255
|
+
const admin = getAdministration(this);
|
|
265
256
|
function reactiveRender() {
|
|
266
257
|
if (!admin.reaction) {
|
|
267
258
|
// Create reaction lazily to support re-mounting #3395
|
|
@@ -272,9 +263,9 @@
|
|
|
272
263
|
mobxReactLite._observerFinalizationRegistry.register(this, admin, this);
|
|
273
264
|
}
|
|
274
265
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
admin.reaction.track(
|
|
266
|
+
let error = undefined;
|
|
267
|
+
let renderResult = undefined;
|
|
268
|
+
admin.reaction.track(() => {
|
|
278
269
|
try {
|
|
279
270
|
// TODO@major
|
|
280
271
|
// Optimization: replace with _allowStateChangesStart/End (not available in mobx@6.0.0)
|
|
@@ -291,7 +282,7 @@
|
|
|
291
282
|
return reactiveRender;
|
|
292
283
|
}
|
|
293
284
|
function createReaction(admin) {
|
|
294
|
-
return new mobx.Reaction(admin.name
|
|
285
|
+
return new mobx.Reaction(`${admin.name}.render()`, () => {
|
|
295
286
|
if (!admin.mounted) {
|
|
296
287
|
// This is neccessary to avoid react warning about calling forceUpdate on component that isn't mounted yet.
|
|
297
288
|
// This happens when component is abandoned after render - our reaction is already created and reacts to changes.
|
|
@@ -327,15 +318,17 @@
|
|
|
327
318
|
return {
|
|
328
319
|
configurable: true,
|
|
329
320
|
enumerable: true,
|
|
330
|
-
get
|
|
331
|
-
|
|
332
|
-
|
|
321
|
+
get() {
|
|
322
|
+
const admin = getAdministration(this);
|
|
323
|
+
const derivation = mobx._getGlobalState().trackingDerivation;
|
|
333
324
|
if (derivation && derivation !== admin.reaction) {
|
|
334
|
-
throw new Error(
|
|
325
|
+
throw new Error(`[mobx-react] Cannot read "${admin.name}.${key}" in a reactive context, as it isn't observable.
|
|
326
|
+
Please use component lifecycle method to copy the value into a local observable first.
|
|
327
|
+
See https://github.com/mobxjs/mobx/blob/main/packages/mobx-react/README.md#note-on-using-props-and-state-in-derivations`);
|
|
335
328
|
}
|
|
336
329
|
return admin[key];
|
|
337
330
|
},
|
|
338
|
-
set
|
|
331
|
+
set(value) {
|
|
339
332
|
getAdministration(this)[key] = value;
|
|
340
333
|
}
|
|
341
334
|
};
|
|
@@ -345,10 +338,7 @@
|
|
|
345
338
|
if (context && context.kind !== "class") {
|
|
346
339
|
throw new Error("The @observer decorator can be used on classes only");
|
|
347
340
|
}
|
|
348
|
-
if (component
|
|
349
|
-
console.warn("Mobx observer: You are trying to use `observer` on a component that already has `inject`. Please apply `observer` before applying `inject`");
|
|
350
|
-
}
|
|
351
|
-
if (Object.prototype.isPrototypeOf.call(React.Component, component) || Object.prototype.isPrototypeOf.call(React.PureComponent, component)) {
|
|
341
|
+
if (Object.prototype.isPrototypeOf.call(React__namespace.Component, component) || Object.prototype.isPrototypeOf.call(React__namespace.PureComponent, component)) {
|
|
352
342
|
// Class component
|
|
353
343
|
return makeClassComponentObserver(component);
|
|
354
344
|
} else {
|
|
@@ -357,308 +347,6 @@
|
|
|
357
347
|
}
|
|
358
348
|
}
|
|
359
349
|
|
|
360
|
-
function _extends() {
|
|
361
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
362
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
363
|
-
var t = arguments[e];
|
|
364
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
365
|
-
}
|
|
366
|
-
return n;
|
|
367
|
-
}, _extends.apply(null, arguments);
|
|
368
|
-
}
|
|
369
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
370
|
-
if (null == r) return {};
|
|
371
|
-
var t = {};
|
|
372
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
373
|
-
if (e.indexOf(n) >= 0) continue;
|
|
374
|
-
t[n] = r[n];
|
|
375
|
-
}
|
|
376
|
-
return t;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
var _excluded = ["children"];
|
|
380
|
-
var MobXProviderContext = /*#__PURE__*/React__default.createContext({});
|
|
381
|
-
function Provider(props) {
|
|
382
|
-
var children = props.children,
|
|
383
|
-
stores = _objectWithoutPropertiesLoose(props, _excluded);
|
|
384
|
-
var parentValue = React__default.useContext(MobXProviderContext);
|
|
385
|
-
var mutableProviderRef = React__default.useRef(_extends({}, parentValue, stores));
|
|
386
|
-
var value = mutableProviderRef.current;
|
|
387
|
-
{
|
|
388
|
-
var newValue = _extends({}, value, stores); // spread in previous state for the context based stores
|
|
389
|
-
if (!shallowEqual(value, newValue)) {
|
|
390
|
-
throw new Error("MobX Provider: The set of provided stores has changed. See: https://github.com/mobxjs/mobx-react#the-set-of-provided-stores-has-changed-error.");
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
return React__default.createElement(MobXProviderContext.Provider, {
|
|
394
|
-
value: value
|
|
395
|
-
}, children);
|
|
396
|
-
}
|
|
397
|
-
Provider.displayName = "MobXProvider";
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Store Injection
|
|
401
|
-
*/
|
|
402
|
-
function createStoreInjector(grabStoresFn, component, injectNames, makeReactive) {
|
|
403
|
-
// Support forward refs
|
|
404
|
-
var Injector = React__default.forwardRef(function (props, ref) {
|
|
405
|
-
var newProps = _extends({}, props);
|
|
406
|
-
var context = React__default.useContext(MobXProviderContext);
|
|
407
|
-
Object.assign(newProps, grabStoresFn(context || {}, newProps) || {});
|
|
408
|
-
if (ref) {
|
|
409
|
-
newProps.ref = ref;
|
|
410
|
-
}
|
|
411
|
-
return React__default.createElement(component, newProps);
|
|
412
|
-
});
|
|
413
|
-
if (makeReactive) Injector = observer(Injector);
|
|
414
|
-
Injector["isMobxInjector"] = true; // assigned late to suppress observer warning
|
|
415
|
-
// Static fields from component should be visible on the generated Injector
|
|
416
|
-
copyStaticProperties(component, Injector);
|
|
417
|
-
Injector["wrappedComponent"] = component;
|
|
418
|
-
Injector.displayName = getInjectName(component, injectNames);
|
|
419
|
-
return Injector;
|
|
420
|
-
}
|
|
421
|
-
function getInjectName(component, injectNames) {
|
|
422
|
-
var displayName;
|
|
423
|
-
var componentName = component.displayName || component.name || component.constructor && component.constructor.name || "Component";
|
|
424
|
-
if (injectNames) displayName = "inject-with-" + injectNames + "(" + componentName + ")";else displayName = "inject(" + componentName + ")";
|
|
425
|
-
return displayName;
|
|
426
|
-
}
|
|
427
|
-
function grabStoresByName(storeNames) {
|
|
428
|
-
return function (baseStores, nextProps) {
|
|
429
|
-
storeNames.forEach(function (storeName) {
|
|
430
|
-
if (storeName in nextProps // prefer props over stores
|
|
431
|
-
) return;
|
|
432
|
-
if (!(storeName in baseStores)) throw new Error("MobX injector: Store '" + storeName + "' is not available! Make sure it is provided by some Provider");
|
|
433
|
-
nextProps[storeName] = baseStores[storeName];
|
|
434
|
-
});
|
|
435
|
-
return nextProps;
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* higher order component that injects stores to a child.
|
|
440
|
-
* takes either a varargs list of strings, which are stores read from the context,
|
|
441
|
-
* or a function that manually maps the available stores from the context to props:
|
|
442
|
-
* storesToProps(mobxStores, props, context) => newProps
|
|
443
|
-
*/
|
|
444
|
-
function inject() {
|
|
445
|
-
for (var _len = arguments.length, storeNames = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
446
|
-
storeNames[_key] = arguments[_key];
|
|
447
|
-
}
|
|
448
|
-
if (typeof arguments[0] === "function") {
|
|
449
|
-
var grabStoresFn = arguments[0];
|
|
450
|
-
return function (componentClass) {
|
|
451
|
-
return createStoreInjector(grabStoresFn, componentClass, grabStoresFn.name, true);
|
|
452
|
-
};
|
|
453
|
-
} else {
|
|
454
|
-
return function (componentClass) {
|
|
455
|
-
return createStoreInjector(grabStoresByName(storeNames), componentClass, storeNames.join("-"), false);
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
var reactMajorVersion = /*#__PURE__*/Number.parseInt( /*#__PURE__*/React__default.version.split(".")[0]);
|
|
461
|
-
var warnedAboutDisposeOnUnmountDeprecated = false;
|
|
462
|
-
var protoStoreKey = /*#__PURE__*/Symbol("disposeOnUnmountProto");
|
|
463
|
-
var instStoreKey = /*#__PURE__*/Symbol("disposeOnUnmountInst");
|
|
464
|
-
function runDisposersOnWillUnmount() {
|
|
465
|
-
var _this = this;
|
|
466
|
-
[].concat(this[protoStoreKey] || [], this[instStoreKey] || []).forEach(function (propKeyOrFunction) {
|
|
467
|
-
var prop = typeof propKeyOrFunction === "string" ? _this[propKeyOrFunction] : propKeyOrFunction;
|
|
468
|
-
if (prop !== undefined && prop !== null) {
|
|
469
|
-
if (Array.isArray(prop)) prop.map(function (f) {
|
|
470
|
-
return f();
|
|
471
|
-
});else prop();
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* @deprecated `disposeOnUnmount` is not compatible with React 18 and higher.
|
|
477
|
-
*/
|
|
478
|
-
function disposeOnUnmount(target, propertyKeyOrFunction) {
|
|
479
|
-
if (Array.isArray(propertyKeyOrFunction)) {
|
|
480
|
-
return propertyKeyOrFunction.map(function (fn) {
|
|
481
|
-
return disposeOnUnmount(target, fn);
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
if (!warnedAboutDisposeOnUnmountDeprecated) {
|
|
485
|
-
if (reactMajorVersion >= 18) {
|
|
486
|
-
console.error("[mobx-react] disposeOnUnmount is not compatible with React 18 and higher. Don't use it.");
|
|
487
|
-
} else {
|
|
488
|
-
console.warn("[mobx-react] disposeOnUnmount is deprecated. It won't work correctly with React 18 and higher.");
|
|
489
|
-
}
|
|
490
|
-
warnedAboutDisposeOnUnmountDeprecated = true;
|
|
491
|
-
}
|
|
492
|
-
var c = Object.getPrototypeOf(target).constructor;
|
|
493
|
-
var c2 = Object.getPrototypeOf(target.constructor);
|
|
494
|
-
// Special case for react-hot-loader
|
|
495
|
-
var c3 = Object.getPrototypeOf(Object.getPrototypeOf(target));
|
|
496
|
-
if (!(c === React__default.Component || c === React__default.PureComponent || c2 === React__default.Component || c2 === React__default.PureComponent || c3 === React__default.Component || c3 === React__default.PureComponent)) {
|
|
497
|
-
throw new Error("[mobx-react] disposeOnUnmount only supports direct subclasses of React.Component or React.PureComponent.");
|
|
498
|
-
}
|
|
499
|
-
if (typeof propertyKeyOrFunction !== "string" && typeof propertyKeyOrFunction !== "function" && !Array.isArray(propertyKeyOrFunction)) {
|
|
500
|
-
throw new Error("[mobx-react] disposeOnUnmount only works if the parameter is either a property key or a function.");
|
|
501
|
-
}
|
|
502
|
-
// decorator's target is the prototype, so it doesn't have any instance properties like props
|
|
503
|
-
var isDecorator = typeof propertyKeyOrFunction === "string";
|
|
504
|
-
// add property key / function we want run (disposed) to the store
|
|
505
|
-
var componentWasAlreadyModified = !!target[protoStoreKey] || !!target[instStoreKey];
|
|
506
|
-
var store = isDecorator ?
|
|
507
|
-
// decorators are added to the prototype store
|
|
508
|
-
target[protoStoreKey] || (target[protoStoreKey] = []) :
|
|
509
|
-
// functions are added to the instance store
|
|
510
|
-
target[instStoreKey] || (target[instStoreKey] = []);
|
|
511
|
-
store.push(propertyKeyOrFunction);
|
|
512
|
-
// tweak the component class componentWillUnmount if not done already
|
|
513
|
-
if (!componentWasAlreadyModified) {
|
|
514
|
-
patch(target, "componentWillUnmount", runDisposersOnWillUnmount);
|
|
515
|
-
}
|
|
516
|
-
// return the disposer as is if invoked as a non decorator
|
|
517
|
-
if (typeof propertyKeyOrFunction !== "string") {
|
|
518
|
-
return propertyKeyOrFunction;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// Copied from React.PropTypes
|
|
523
|
-
function createChainableTypeChecker(validator) {
|
|
524
|
-
function checkType(isRequired, props, propName, componentName, location, propFullName) {
|
|
525
|
-
for (var _len = arguments.length, rest = new Array(_len > 6 ? _len - 6 : 0), _key = 6; _key < _len; _key++) {
|
|
526
|
-
rest[_key - 6] = arguments[_key];
|
|
527
|
-
}
|
|
528
|
-
return mobx.untracked(function () {
|
|
529
|
-
componentName = componentName || "<<anonymous>>";
|
|
530
|
-
propFullName = propFullName || propName;
|
|
531
|
-
if (props[propName] == null) {
|
|
532
|
-
if (isRequired) {
|
|
533
|
-
var actual = props[propName] === null ? "null" : "undefined";
|
|
534
|
-
return new Error("The " + location + " `" + propFullName + "` is marked as required " + "in `" + componentName + "`, but its value is `" + actual + "`.");
|
|
535
|
-
}
|
|
536
|
-
return null;
|
|
537
|
-
} else {
|
|
538
|
-
// @ts-ignore rest arg is necessary for some React internals - fails tests otherwise
|
|
539
|
-
return validator.apply(void 0, [props, propName, componentName, location, propFullName].concat(rest));
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
var chainedCheckType = checkType.bind(null, false);
|
|
544
|
-
// Add isRequired to satisfy Requirable
|
|
545
|
-
chainedCheckType.isRequired = checkType.bind(null, true);
|
|
546
|
-
return chainedCheckType;
|
|
547
|
-
}
|
|
548
|
-
// Copied from React.PropTypes
|
|
549
|
-
function isSymbol(propType, propValue) {
|
|
550
|
-
// Native Symbol.
|
|
551
|
-
if (propType === "symbol") {
|
|
552
|
-
return true;
|
|
553
|
-
}
|
|
554
|
-
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
|
555
|
-
if (propValue["@@toStringTag"] === "Symbol") {
|
|
556
|
-
return true;
|
|
557
|
-
}
|
|
558
|
-
// Fallback for non-spec compliant Symbols which are polyfilled.
|
|
559
|
-
if (typeof Symbol === "function" && propValue instanceof Symbol) {
|
|
560
|
-
return true;
|
|
561
|
-
}
|
|
562
|
-
return false;
|
|
563
|
-
}
|
|
564
|
-
// Copied from React.PropTypes
|
|
565
|
-
function getPropType(propValue) {
|
|
566
|
-
var propType = typeof propValue;
|
|
567
|
-
if (Array.isArray(propValue)) {
|
|
568
|
-
return "array";
|
|
569
|
-
}
|
|
570
|
-
if (propValue instanceof RegExp) {
|
|
571
|
-
// Old webkits (at least until Android 4.0) return 'function' rather than
|
|
572
|
-
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
|
|
573
|
-
// passes PropTypes.object.
|
|
574
|
-
return "object";
|
|
575
|
-
}
|
|
576
|
-
if (isSymbol(propType, propValue)) {
|
|
577
|
-
return "symbol";
|
|
578
|
-
}
|
|
579
|
-
return propType;
|
|
580
|
-
}
|
|
581
|
-
// This handles more types than `getPropType`. Only used for error messages.
|
|
582
|
-
// Copied from React.PropTypes
|
|
583
|
-
function getPreciseType(propValue) {
|
|
584
|
-
var propType = getPropType(propValue);
|
|
585
|
-
if (propType === "object") {
|
|
586
|
-
if (propValue instanceof Date) {
|
|
587
|
-
return "date";
|
|
588
|
-
} else if (propValue instanceof RegExp) {
|
|
589
|
-
return "regexp";
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
return propType;
|
|
593
|
-
}
|
|
594
|
-
function createObservableTypeCheckerCreator(allowNativeType, mobxType) {
|
|
595
|
-
return createChainableTypeChecker(function (props, propName, componentName, location, propFullName) {
|
|
596
|
-
return mobx.untracked(function () {
|
|
597
|
-
if (allowNativeType) {
|
|
598
|
-
if (getPropType(props[propName]) === mobxType.toLowerCase()) return null;
|
|
599
|
-
}
|
|
600
|
-
var mobxChecker;
|
|
601
|
-
switch (mobxType) {
|
|
602
|
-
case "Array":
|
|
603
|
-
mobxChecker = mobx.isObservableArray;
|
|
604
|
-
break;
|
|
605
|
-
case "Object":
|
|
606
|
-
mobxChecker = mobx.isObservableObject;
|
|
607
|
-
break;
|
|
608
|
-
case "Map":
|
|
609
|
-
mobxChecker = mobx.isObservableMap;
|
|
610
|
-
break;
|
|
611
|
-
default:
|
|
612
|
-
throw new Error("Unexpected mobxType: " + mobxType);
|
|
613
|
-
}
|
|
614
|
-
var propValue = props[propName];
|
|
615
|
-
if (!mobxChecker(propValue)) {
|
|
616
|
-
var preciseType = getPreciseType(propValue);
|
|
617
|
-
var nativeTypeExpectationMessage = allowNativeType ? " or javascript `" + mobxType.toLowerCase() + "`" : "";
|
|
618
|
-
return new Error("Invalid prop `" + propFullName + "` of type `" + preciseType + "` supplied to" + " `" + componentName + "`, expected `mobx.Observable" + mobxType + "`" + nativeTypeExpectationMessage + ".");
|
|
619
|
-
}
|
|
620
|
-
return null;
|
|
621
|
-
});
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
function createObservableArrayOfTypeChecker(allowNativeType, typeChecker) {
|
|
625
|
-
return createChainableTypeChecker(function (props, propName, componentName, location, propFullName) {
|
|
626
|
-
for (var _len2 = arguments.length, rest = new Array(_len2 > 5 ? _len2 - 5 : 0), _key2 = 5; _key2 < _len2; _key2++) {
|
|
627
|
-
rest[_key2 - 5] = arguments[_key2];
|
|
628
|
-
}
|
|
629
|
-
return mobx.untracked(function () {
|
|
630
|
-
if (typeof typeChecker !== "function") {
|
|
631
|
-
return new Error("Property `" + propFullName + "` of component `" + componentName + "` has " + "invalid PropType notation.");
|
|
632
|
-
} else {
|
|
633
|
-
var error = createObservableTypeCheckerCreator(allowNativeType, "Array")(props, propName, componentName, location, propFullName);
|
|
634
|
-
if (error instanceof Error) return error;
|
|
635
|
-
var propValue = props[propName];
|
|
636
|
-
for (var i = 0; i < propValue.length; i++) {
|
|
637
|
-
error = typeChecker.apply(void 0, [propValue, i, componentName, location, propFullName + "[" + i + "]"].concat(rest));
|
|
638
|
-
if (error instanceof Error) return error;
|
|
639
|
-
}
|
|
640
|
-
return null;
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
var observableArray = /*#__PURE__*/createObservableTypeCheckerCreator(false, "Array");
|
|
646
|
-
var observableArrayOf = /*#__PURE__*/createObservableArrayOfTypeChecker.bind(null, false);
|
|
647
|
-
var observableMap = /*#__PURE__*/createObservableTypeCheckerCreator(false, "Map");
|
|
648
|
-
var observableObject = /*#__PURE__*/createObservableTypeCheckerCreator(false, "Object");
|
|
649
|
-
var arrayOrObservableArray = /*#__PURE__*/createObservableTypeCheckerCreator(true, "Array");
|
|
650
|
-
var arrayOrObservableArrayOf = /*#__PURE__*/createObservableArrayOfTypeChecker.bind(null, true);
|
|
651
|
-
var objectOrObservableObject = /*#__PURE__*/createObservableTypeCheckerCreator(true, "Object");
|
|
652
|
-
var PropTypes = {
|
|
653
|
-
observableArray: observableArray,
|
|
654
|
-
observableArrayOf: observableArrayOf,
|
|
655
|
-
observableMap: observableMap,
|
|
656
|
-
observableObject: observableObject,
|
|
657
|
-
arrayOrObservableArray: arrayOrObservableArray,
|
|
658
|
-
arrayOrObservableArrayOf: arrayOrObservableArrayOf,
|
|
659
|
-
objectOrObservableObject: objectOrObservableObject
|
|
660
|
-
};
|
|
661
|
-
|
|
662
350
|
if (!React.Component) {
|
|
663
351
|
throw new Error("mobx-react requires React to be available");
|
|
664
352
|
}
|
|
@@ -668,66 +356,31 @@
|
|
|
668
356
|
|
|
669
357
|
Object.defineProperty(exports, 'Observer', {
|
|
670
358
|
enumerable: true,
|
|
671
|
-
get: function () {
|
|
672
|
-
return mobxReactLite.Observer;
|
|
673
|
-
}
|
|
359
|
+
get: function () { return mobxReactLite.Observer; }
|
|
674
360
|
});
|
|
675
|
-
Object.defineProperty(exports, '
|
|
361
|
+
Object.defineProperty(exports, '_observerFinalizationRegistry', {
|
|
676
362
|
enumerable: true,
|
|
677
|
-
get: function () {
|
|
678
|
-
return mobxReactLite.enableStaticRendering;
|
|
679
|
-
}
|
|
363
|
+
get: function () { return mobxReactLite._observerFinalizationRegistry; }
|
|
680
364
|
});
|
|
681
|
-
Object.defineProperty(exports, '
|
|
365
|
+
Object.defineProperty(exports, 'clearTimers', {
|
|
682
366
|
enumerable: true,
|
|
683
|
-
get: function () {
|
|
684
|
-
return mobxReactLite.isUsingStaticRendering;
|
|
685
|
-
}
|
|
367
|
+
get: function () { return mobxReactLite.clearTimers; }
|
|
686
368
|
});
|
|
687
|
-
Object.defineProperty(exports, '
|
|
369
|
+
Object.defineProperty(exports, 'enableStaticRendering', {
|
|
688
370
|
enumerable: true,
|
|
689
|
-
get: function () {
|
|
690
|
-
return mobxReactLite.observerBatching;
|
|
691
|
-
}
|
|
371
|
+
get: function () { return mobxReactLite.enableStaticRendering; }
|
|
692
372
|
});
|
|
693
|
-
Object.defineProperty(exports, '
|
|
373
|
+
Object.defineProperty(exports, 'isUsingStaticRendering', {
|
|
694
374
|
enumerable: true,
|
|
695
|
-
get: function () {
|
|
696
|
-
return mobxReactLite.useAsObservableSource;
|
|
697
|
-
}
|
|
375
|
+
get: function () { return mobxReactLite.isUsingStaticRendering; }
|
|
698
376
|
});
|
|
699
377
|
Object.defineProperty(exports, 'useLocalObservable', {
|
|
700
378
|
enumerable: true,
|
|
701
|
-
get: function () {
|
|
702
|
-
return mobxReactLite.useLocalObservable;
|
|
703
|
-
}
|
|
704
|
-
});
|
|
705
|
-
Object.defineProperty(exports, 'useLocalStore', {
|
|
706
|
-
enumerable: true,
|
|
707
|
-
get: function () {
|
|
708
|
-
return mobxReactLite.useLocalStore;
|
|
709
|
-
}
|
|
710
|
-
});
|
|
711
|
-
Object.defineProperty(exports, 'useObserver', {
|
|
712
|
-
enumerable: true,
|
|
713
|
-
get: function () {
|
|
714
|
-
return mobxReactLite.useObserver;
|
|
715
|
-
}
|
|
716
|
-
});
|
|
717
|
-
Object.defineProperty(exports, 'useStaticRendering', {
|
|
718
|
-
enumerable: true,
|
|
719
|
-
get: function () {
|
|
720
|
-
return mobxReactLite.useStaticRendering;
|
|
721
|
-
}
|
|
379
|
+
get: function () { return mobxReactLite.useLocalObservable; }
|
|
722
380
|
});
|
|
723
|
-
exports.MobXProviderContext = MobXProviderContext;
|
|
724
|
-
exports.PropTypes = PropTypes;
|
|
725
|
-
exports.Provider = Provider;
|
|
726
|
-
exports.disposeOnUnmount = disposeOnUnmount;
|
|
727
|
-
exports.inject = inject;
|
|
728
381
|
exports.observer = observer;
|
|
729
382
|
|
|
730
383
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
731
384
|
|
|
732
|
-
}))
|
|
385
|
+
}));
|
|
733
386
|
//# sourceMappingURL=mobxreact.umd.development.js.map
|