mobx 4.15.3 → 4.15.4
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 +4 -0
- package/lib/index.js +7 -0
- package/lib/mobx.es6.js +110 -63
- package/lib/mobx.js +1 -1
- package/lib/mobx.module.js +110 -63
- package/lib/mobx.umd.js +110 -63
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# 5.15.4 / 4.15.4
|
|
2
|
+
|
|
3
|
+
- Fix process.env replacement in build [#2267](https://github.com/mobxjs/mobx/pull/2267) by [@fredyc](https://github.com/fredyc)
|
|
4
|
+
|
|
1
5
|
# 5.15.3 / 4.15.3
|
|
2
6
|
|
|
3
7
|
- Define action name to be as the function name [#2262](https://github.com/mobxjs/mobx/pull/2262) by [@nadavkaner](https://github.com/nadavkaner)
|
package/lib/index.js
ADDED
package/lib/mobx.es6.js
CHANGED
|
@@ -34,6 +34,8 @@ function invariant(check, message) {
|
|
|
34
34
|
*/
|
|
35
35
|
const deprecatedMessages = [];
|
|
36
36
|
function deprecated(msg, thing) {
|
|
37
|
+
if (process.env.NODE_ENV === "production")
|
|
38
|
+
return false;
|
|
37
39
|
if (thing) {
|
|
38
40
|
return deprecated(`'${msg}', use '${thing}' instead.`);
|
|
39
41
|
}
|
|
@@ -113,7 +115,7 @@ function isPropertyConfigurable(object, prop) {
|
|
|
113
115
|
return !descriptor || (descriptor.configurable !== false && descriptor.writable !== false);
|
|
114
116
|
}
|
|
115
117
|
function assertPropertyConfigurable(object, prop) {
|
|
116
|
-
if (!isPropertyConfigurable(object, prop))
|
|
118
|
+
if (process.env.NODE_ENV !== "production" && !isPropertyConfigurable(object, prop))
|
|
117
119
|
fail(`Cannot make property '${prop}' observable, it is not configurable and writable in the target object`);
|
|
118
120
|
}
|
|
119
121
|
function createInstanceofPredicate(name, clazz) {
|
|
@@ -290,7 +292,7 @@ function createPropDecorator(propertyInitiallyEnumerable, propertyCreator) {
|
|
|
290
292
|
propertyCreator(target, prop, descriptor, target, decoratorArguments);
|
|
291
293
|
return null;
|
|
292
294
|
}
|
|
293
|
-
if (!quacksLikeADecorator(arguments))
|
|
295
|
+
if (process.env.NODE_ENV !== "production" && !quacksLikeADecorator(arguments))
|
|
294
296
|
fail("This function is a decorator, but it wasn't invoked like a decorator");
|
|
295
297
|
if (!Object.prototype.hasOwnProperty.call(target, "__mobxDecorators")) {
|
|
296
298
|
const inheritedDecorators = target.__mobxDecorators;
|
|
@@ -350,14 +352,15 @@ function shallowEnhancer(v, _, name) {
|
|
|
350
352
|
return observable.map(v, { name, deep: false });
|
|
351
353
|
if (isES6Set(v))
|
|
352
354
|
return observable.set(v, { name, deep: false });
|
|
353
|
-
return fail(
|
|
355
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
356
|
+
"The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
|
|
354
357
|
}
|
|
355
358
|
function referenceEnhancer(newValue) {
|
|
356
359
|
// never turn into an observable
|
|
357
360
|
return newValue;
|
|
358
361
|
}
|
|
359
362
|
function refStructEnhancer(v, oldValue, name) {
|
|
360
|
-
if (isObservable(v))
|
|
363
|
+
if (process.env.NODE_ENV !== "production" && isObservable(v))
|
|
361
364
|
throw `observable.struct should not be used with observable values`;
|
|
362
365
|
if (deepEqual(v, oldValue))
|
|
363
366
|
return oldValue;
|
|
@@ -367,7 +370,7 @@ function refStructEnhancer(v, oldValue, name) {
|
|
|
367
370
|
function createDecoratorForEnhancer(enhancer) {
|
|
368
371
|
invariant(enhancer);
|
|
369
372
|
const decorator = createPropDecorator(true, (target, propertyName, descriptor, _decoratorTarget, decoratorArgs) => {
|
|
370
|
-
{
|
|
373
|
+
if (process.env.NODE_ENV !== "production") {
|
|
371
374
|
invariant(!descriptor || !descriptor.get, `@observable cannot be used on getter (property "${propertyName}"), use @computed instead.`);
|
|
372
375
|
}
|
|
373
376
|
const initialValue = descriptor
|
|
@@ -379,7 +382,7 @@ function createDecoratorForEnhancer(enhancer) {
|
|
|
379
382
|
});
|
|
380
383
|
const res =
|
|
381
384
|
// Extra process checks, as this happens during module initialization
|
|
382
|
-
typeof process !== "undefined" && process.env &&
|
|
385
|
+
typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production"
|
|
383
386
|
? function observableDecorator() {
|
|
384
387
|
// This wrapper function is just to detect illegal decorator invocations, deprecate in a next version
|
|
385
388
|
// and simply return the created prop decorator
|
|
@@ -415,7 +418,7 @@ function asCreateObservableOptions(thing) {
|
|
|
415
418
|
return defaultCreateObservableOptions;
|
|
416
419
|
if (typeof thing === "string")
|
|
417
420
|
return { name: thing, deep: true };
|
|
418
|
-
{
|
|
421
|
+
if (process.env.NODE_ENV !== "production") {
|
|
419
422
|
if (typeof thing !== "object")
|
|
420
423
|
return fail("expected options object");
|
|
421
424
|
Object.keys(thing).forEach(assertValidOption);
|
|
@@ -459,7 +462,8 @@ function createObservable(v, arg2, arg3) {
|
|
|
459
462
|
if (res !== v)
|
|
460
463
|
return res;
|
|
461
464
|
// otherwise, just box it
|
|
462
|
-
fail(
|
|
465
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
466
|
+
`The provided value could not be converted into an observable. If you want just create an observable reference to the object use 'observable.box(value)'`);
|
|
463
467
|
}
|
|
464
468
|
const observableFactories = {
|
|
465
469
|
box(value, options) {
|
|
@@ -526,7 +530,7 @@ const observable = createObservable;
|
|
|
526
530
|
Object.keys(observableFactories).forEach(name => (observable[name] = observableFactories[name]));
|
|
527
531
|
function incorrectlyUsedAsDecorator(methodName) {
|
|
528
532
|
fail(
|
|
529
|
-
//
|
|
533
|
+
// process.env.NODE_ENV !== "production" &&
|
|
530
534
|
`Expected one or two arguments to observable.${methodName}. Did you accidentally try to use observable.${methodName} as decorator?`);
|
|
531
535
|
}
|
|
532
536
|
|
|
@@ -553,7 +557,7 @@ const computed = function computed(arg1, arg2, arg3) {
|
|
|
553
557
|
return computedDecorator.apply(null, arguments);
|
|
554
558
|
}
|
|
555
559
|
// computed(expr, options?)
|
|
556
|
-
{
|
|
560
|
+
if (process.env.NODE_ENV !== "production") {
|
|
557
561
|
invariant(typeof arg1 === "function", "First argument to `computed` should be an expression.");
|
|
558
562
|
invariant(arguments.length < 3, "Computed takes one or two arguments if used as function");
|
|
559
563
|
}
|
|
@@ -660,7 +664,7 @@ function shouldCompute(derivation) {
|
|
|
660
664
|
// function invariantShouldCompute(derivation: IDerivation) {
|
|
661
665
|
// const newDepState = (derivation as any).dependenciesState
|
|
662
666
|
// if (
|
|
663
|
-
//
|
|
667
|
+
// process.env.NODE_ENV === "production" &&
|
|
664
668
|
// (newDepState === IDerivationState.POSSIBLY_STALE ||
|
|
665
669
|
// newDepState === IDerivationState.NOT_TRACKING)
|
|
666
670
|
// )
|
|
@@ -673,16 +677,19 @@ function checkIfStateModificationsAreAllowed(atom) {
|
|
|
673
677
|
const hasObservers = atom.observers.length > 0;
|
|
674
678
|
// Should never be possible to change an observed observable from inside computed, see #798
|
|
675
679
|
if (globalState.computationDepth > 0 && hasObservers)
|
|
676
|
-
fail(
|
|
680
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
681
|
+
`Computed values are not allowed to cause side effects by changing observables that are already being observed. Tried to modify: ${atom.name}`);
|
|
677
682
|
// Should not be possible to change observed state outside strict mode, except during initialization, see #563
|
|
678
683
|
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "strict"))
|
|
679
|
-
fail(
|
|
684
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
685
|
+
(globalState.enforceActions
|
|
680
686
|
? "Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an `action` if this change is intended. Tried to modify: "
|
|
681
687
|
: "Side effects like changing state are not allowed at this point. Are you trying to modify state from, for example, the render function of a React component? Tried to modify: ") +
|
|
682
688
|
atom.name);
|
|
683
689
|
}
|
|
684
690
|
function checkIfStateReadsAreAllowed(observable) {
|
|
685
|
-
if (
|
|
691
|
+
if (process.env.NODE_ENV !== "production" &&
|
|
692
|
+
!globalState.allowStateReads &&
|
|
686
693
|
globalState.observableRequiresReaction) {
|
|
687
694
|
console.warn(`[mobx] Observable ${observable.name} being read outside a reactive context`);
|
|
688
695
|
}
|
|
@@ -723,6 +730,8 @@ function trackDerivedFunction(derivation, f, context) {
|
|
|
723
730
|
return result;
|
|
724
731
|
}
|
|
725
732
|
function warnAboutDerivationWithoutDependencies(derivation) {
|
|
733
|
+
if (process.env.NODE_ENV === "production")
|
|
734
|
+
return;
|
|
726
735
|
if (globalState.reactionRequiresObservable || derivation.requiresObservable) {
|
|
727
736
|
console.warn(`[mobx] Derivation ${derivation.name} is created/updated without reading any observable value`);
|
|
728
737
|
}
|
|
@@ -837,7 +846,7 @@ let nextActionId = 1;
|
|
|
837
846
|
const functionNameDescriptor = Object.getOwnPropertyDescriptor(() => { }, "name");
|
|
838
847
|
const isFunctionNameConfigurable = functionNameDescriptor && functionNameDescriptor.configurable;
|
|
839
848
|
function createAction(actionName, fn) {
|
|
840
|
-
{
|
|
849
|
+
if (process.env.NODE_ENV !== "production") {
|
|
841
850
|
invariant(typeof fn === "function", "`action` can only be invoked on functions");
|
|
842
851
|
if (typeof actionName !== "string" || !actionName)
|
|
843
852
|
fail(`actions should have valid names, got: '${actionName}'`);
|
|
@@ -845,7 +854,7 @@ function createAction(actionName, fn) {
|
|
|
845
854
|
const res = function () {
|
|
846
855
|
return executeAction(actionName, fn, this, arguments);
|
|
847
856
|
};
|
|
848
|
-
{
|
|
857
|
+
if (process.env.NODE_ENV !== "production") {
|
|
849
858
|
if (isFunctionNameConfigurable) {
|
|
850
859
|
Object.defineProperty(res, "name", { value: actionName });
|
|
851
860
|
}
|
|
@@ -1156,7 +1165,8 @@ class ComputedValue {
|
|
|
1156
1165
|
}
|
|
1157
1166
|
}
|
|
1158
1167
|
else
|
|
1159
|
-
invariant(false,
|
|
1168
|
+
invariant(false, process.env.NODE_ENV !== "production" &&
|
|
1169
|
+
`[ComputedValue '${this.name}'] It is not possible to assign a new value to a computed value.`);
|
|
1160
1170
|
}
|
|
1161
1171
|
trackAndCompute() {
|
|
1162
1172
|
if (isSpyEnabled()) {
|
|
@@ -1229,6 +1239,8 @@ class ComputedValue {
|
|
|
1229
1239
|
});
|
|
1230
1240
|
}
|
|
1231
1241
|
warnAboutUntrackedRead() {
|
|
1242
|
+
if (process.env.NODE_ENV === "production")
|
|
1243
|
+
return;
|
|
1232
1244
|
if (this.requiresReaction === true) {
|
|
1233
1245
|
fail(`[mobx] Computed value ${this.name} is read outside a reactive context`);
|
|
1234
1246
|
}
|
|
@@ -1877,12 +1889,12 @@ function spy(listener) {
|
|
|
1877
1889
|
}
|
|
1878
1890
|
|
|
1879
1891
|
function dontReassignFields() {
|
|
1880
|
-
fail("@action fields are not reassignable");
|
|
1892
|
+
fail(process.env.NODE_ENV !== "production" && "@action fields are not reassignable");
|
|
1881
1893
|
}
|
|
1882
1894
|
function namedActionDecorator(name) {
|
|
1883
1895
|
return function (target, prop, descriptor) {
|
|
1884
1896
|
if (descriptor) {
|
|
1885
|
-
if (descriptor.get !== undefined) {
|
|
1897
|
+
if (process.env.NODE_ENV !== "production" && descriptor.get !== undefined) {
|
|
1886
1898
|
return fail("@action cannot be used with getters");
|
|
1887
1899
|
}
|
|
1888
1900
|
// babel / typescript
|
|
@@ -1983,7 +1995,7 @@ function runInAction(arg1, arg2) {
|
|
|
1983
1995
|
// TODO: deprecate?
|
|
1984
1996
|
const actionName = typeof arg1 === "string" ? arg1 : arg1.name || "<unnamed action>";
|
|
1985
1997
|
const fn = typeof arg1 === "function" ? arg1 : arg2;
|
|
1986
|
-
{
|
|
1998
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1987
1999
|
invariant(typeof fn === "function" && fn.length === 0, "`runInAction` expects a function without arguments");
|
|
1988
2000
|
if (typeof actionName !== "string" || !actionName)
|
|
1989
2001
|
fail(`actions should have valid names, got: '${actionName}'`);
|
|
@@ -2004,7 +2016,7 @@ function defineBoundAction(target, propertyName, fn) {
|
|
|
2004
2016
|
* @returns disposer function, which can be used to stop the view from being updated in the future.
|
|
2005
2017
|
*/
|
|
2006
2018
|
function autorun(view, opts = EMPTY_OBJECT) {
|
|
2007
|
-
{
|
|
2019
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2008
2020
|
invariant(typeof view === "function", "Autorun expects a function as first argument");
|
|
2009
2021
|
invariant(isAction(view) === false, "Autorun does not accept actions since actions are untrackable");
|
|
2010
2022
|
}
|
|
@@ -2051,7 +2063,7 @@ function reaction(expression, effect, opts = EMPTY_OBJECT) {
|
|
|
2051
2063
|
opts = { fireImmediately: opts };
|
|
2052
2064
|
deprecated(`Using fireImmediately as argument is deprecated. Use '{ fireImmediately: true }' instead`);
|
|
2053
2065
|
}
|
|
2054
|
-
{
|
|
2066
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2055
2067
|
invariant(typeof expression === "function", "First argument to reaction should be a function");
|
|
2056
2068
|
invariant(typeof opts === "object", "Third argument of reactions should be an object");
|
|
2057
2069
|
}
|
|
@@ -2116,7 +2128,7 @@ function interceptHook(hook, thing, arg2, arg3) {
|
|
|
2116
2128
|
const cb = typeof arg3 === "function" ? arg3 : arg2;
|
|
2117
2129
|
const orig = atom[hook];
|
|
2118
2130
|
if (typeof orig !== "function")
|
|
2119
|
-
return fail("Not an atom that can be (un)observed");
|
|
2131
|
+
return fail(process.env.NODE_ENV !== "production" && "Not an atom that can be (un)observed");
|
|
2120
2132
|
atom[hook] = function () {
|
|
2121
2133
|
orig.call(this);
|
|
2122
2134
|
cb.call(this);
|
|
@@ -2181,7 +2193,7 @@ function configure(options) {
|
|
|
2181
2193
|
}
|
|
2182
2194
|
|
|
2183
2195
|
function decorate(thing, decorators) {
|
|
2184
|
-
if (!isPlainObject(decorators))
|
|
2196
|
+
if (process.env.NODE_ENV !== "production" && !isPlainObject(decorators))
|
|
2185
2197
|
fail("Decorators should be a key value map");
|
|
2186
2198
|
const target = typeof thing === "function" ? thing.prototype : thing;
|
|
2187
2199
|
for (let prop in decorators) {
|
|
@@ -2190,7 +2202,7 @@ function decorate(thing, decorators) {
|
|
|
2190
2202
|
propertyDecorators = [propertyDecorators];
|
|
2191
2203
|
}
|
|
2192
2204
|
// prettier-ignore
|
|
2193
|
-
if (!propertyDecorators.every(decorator => typeof decorator === "function"))
|
|
2205
|
+
if (process.env.NODE_ENV !== "production" && !propertyDecorators.every(decorator => typeof decorator === "function"))
|
|
2194
2206
|
fail(`Decorate: expected a decorator function or array of decorator functions for '${prop}'`);
|
|
2195
2207
|
const descriptor = Object.getOwnPropertyDescriptor(target, prop);
|
|
2196
2208
|
const newDescriptor = propertyDecorators.reduce((accDescriptor, decorator) => decorator(target, prop, accDescriptor), descriptor);
|
|
@@ -2205,7 +2217,7 @@ function extendShallowObservable(target, properties, decorators) {
|
|
|
2205
2217
|
return extendObservable(target, properties, decorators, shallowCreateObservableOptions);
|
|
2206
2218
|
}
|
|
2207
2219
|
function extendObservable(target, properties, decorators, options) {
|
|
2208
|
-
{
|
|
2220
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2209
2221
|
invariant(arguments.length >= 2 && arguments.length <= 4, "'extendObservable' expected 2-4 arguments");
|
|
2210
2222
|
invariant(typeof target === "object", "'extendObservable' expects an object as first argument");
|
|
2211
2223
|
invariant(!isObservableMap(target), "'extendObservable' should not be used on maps, use map.merge instead");
|
|
@@ -2223,7 +2235,7 @@ function extendObservable(target, properties, decorators, options) {
|
|
|
2223
2235
|
try {
|
|
2224
2236
|
for (let key in properties) {
|
|
2225
2237
|
const descriptor = Object.getOwnPropertyDescriptor(properties, key);
|
|
2226
|
-
{
|
|
2238
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2227
2239
|
if (isComputed(descriptor.value))
|
|
2228
2240
|
fail(`Passing a 'computed' as initial property value is no longer supported by extendObservable. Use a getter or decorator instead`);
|
|
2229
2241
|
}
|
|
@@ -2232,7 +2244,7 @@ function extendObservable(target, properties, decorators, options) {
|
|
|
2232
2244
|
: descriptor.get
|
|
2233
2245
|
? computedDecorator
|
|
2234
2246
|
: defaultDecorator;
|
|
2235
|
-
if (typeof decorator !== "function")
|
|
2247
|
+
if (process.env.NODE_ENV !== "production" && typeof decorator !== "function")
|
|
2236
2248
|
return fail(`Not a valid decorator for '${key}', got: ${decorator}`);
|
|
2237
2249
|
const resultDescriptor = decorator(target, key, descriptor, true);
|
|
2238
2250
|
if (resultDescriptor // otherwise, assume already applied, due to `applyToInstance`
|
|
@@ -2279,7 +2291,7 @@ function isFlowCancellationError(error) {
|
|
|
2279
2291
|
}
|
|
2280
2292
|
function flow(generator) {
|
|
2281
2293
|
if (arguments.length !== 1)
|
|
2282
|
-
fail(`Flow expects one 1 argument and cannot be used as decorator`);
|
|
2294
|
+
fail(!!process.env.NODE_ENV && `Flow expects one 1 argument and cannot be used as decorator`);
|
|
2283
2295
|
const name = generator.name || "<unnamed flow>";
|
|
2284
2296
|
// Implementation based on https://github.com/tj/co/blob/master/index.js
|
|
2285
2297
|
return function () {
|
|
@@ -2359,14 +2371,16 @@ function interceptReads(thing, propOrHandler, handler) {
|
|
|
2359
2371
|
}
|
|
2360
2372
|
else if (isObservableObject(thing)) {
|
|
2361
2373
|
if (typeof propOrHandler !== "string")
|
|
2362
|
-
return fail(
|
|
2374
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2375
|
+
`InterceptReads can only be used with a specific property, not with an object in general`);
|
|
2363
2376
|
target = getAdministration(thing, propOrHandler);
|
|
2364
2377
|
}
|
|
2365
2378
|
else {
|
|
2366
|
-
return fail(
|
|
2379
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2380
|
+
`Expected observable map, object or array as first array`);
|
|
2367
2381
|
}
|
|
2368
2382
|
if (target.dehancer !== undefined)
|
|
2369
|
-
return fail(`An intercept reader was already established`);
|
|
2383
|
+
return fail(process.env.NODE_ENV !== "production" && `An intercept reader was already established`);
|
|
2370
2384
|
target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
|
|
2371
2385
|
return () => {
|
|
2372
2386
|
target.dehancer = undefined;
|
|
@@ -2401,12 +2415,14 @@ function _isComputed(value, property) {
|
|
|
2401
2415
|
}
|
|
2402
2416
|
function isComputed(value) {
|
|
2403
2417
|
if (arguments.length > 1)
|
|
2404
|
-
return fail(
|
|
2418
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2419
|
+
`isComputed expects only 1 argument. Use isObservableProp to inspect the observability of a property`);
|
|
2405
2420
|
return _isComputed(value);
|
|
2406
2421
|
}
|
|
2407
2422
|
function isComputedProp(value, propName) {
|
|
2408
2423
|
if (typeof propName !== "string")
|
|
2409
|
-
return fail(
|
|
2424
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2425
|
+
`isComputed expected a property name as second argument`);
|
|
2410
2426
|
return _isComputed(value, propName);
|
|
2411
2427
|
}
|
|
2412
2428
|
|
|
@@ -2414,7 +2430,8 @@ function _isObservable(value, property) {
|
|
|
2414
2430
|
if (value === null || value === undefined)
|
|
2415
2431
|
return false;
|
|
2416
2432
|
if (property !== undefined) {
|
|
2417
|
-
if (
|
|
2433
|
+
if (process.env.NODE_ENV !== "production" &&
|
|
2434
|
+
(isObservableMap(value) || isObservableArray(value)))
|
|
2418
2435
|
return fail("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
|
|
2419
2436
|
if (isObservableObject(value)) {
|
|
2420
2437
|
const o = value.$mobx;
|
|
@@ -2431,12 +2448,13 @@ function _isObservable(value, property) {
|
|
|
2431
2448
|
}
|
|
2432
2449
|
function isObservable(value) {
|
|
2433
2450
|
if (arguments.length !== 1)
|
|
2434
|
-
fail(
|
|
2451
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
2452
|
+
`isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property`);
|
|
2435
2453
|
return _isObservable(value);
|
|
2436
2454
|
}
|
|
2437
2455
|
function isObservableProp(value, propName) {
|
|
2438
2456
|
if (typeof propName !== "string")
|
|
2439
|
-
return fail(`expected a property name as second argument`);
|
|
2457
|
+
return fail(process.env.NODE_ENV !== "production" && `expected a property name as second argument`);
|
|
2440
2458
|
return _isObservable(value, propName);
|
|
2441
2459
|
}
|
|
2442
2460
|
|
|
@@ -2453,7 +2471,8 @@ function keys(obj) {
|
|
|
2453
2471
|
if (isObservableArray(obj)) {
|
|
2454
2472
|
return obj.map((_, index) => index);
|
|
2455
2473
|
}
|
|
2456
|
-
return fail(
|
|
2474
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2475
|
+
"'keys()' can only be used on observable objects, arrays, sets and maps");
|
|
2457
2476
|
}
|
|
2458
2477
|
function values(obj) {
|
|
2459
2478
|
if (isObservableObject(obj)) {
|
|
@@ -2468,7 +2487,8 @@ function values(obj) {
|
|
|
2468
2487
|
if (isObservableArray(obj)) {
|
|
2469
2488
|
return obj.slice();
|
|
2470
2489
|
}
|
|
2471
|
-
return fail(
|
|
2490
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2491
|
+
"'values()' can only be used on observable objects, arrays, sets and maps");
|
|
2472
2492
|
}
|
|
2473
2493
|
function entries(obj) {
|
|
2474
2494
|
if (isObservableObject(obj)) {
|
|
@@ -2483,7 +2503,8 @@ function entries(obj) {
|
|
|
2483
2503
|
if (isObservableArray(obj)) {
|
|
2484
2504
|
return obj.map((key, index) => [index, key]);
|
|
2485
2505
|
}
|
|
2486
|
-
return fail(
|
|
2506
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2507
|
+
"'entries()' can only be used on observable objects, arrays and maps");
|
|
2487
2508
|
}
|
|
2488
2509
|
function set(obj, key, value) {
|
|
2489
2510
|
if (arguments.length === 2 && !isObservableSet(obj)) {
|
|
@@ -2525,7 +2546,8 @@ function set(obj, key, value) {
|
|
|
2525
2546
|
endBatch();
|
|
2526
2547
|
}
|
|
2527
2548
|
else {
|
|
2528
|
-
return fail(
|
|
2549
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2550
|
+
"'set()' can only be used on observable objects, arrays and maps");
|
|
2529
2551
|
}
|
|
2530
2552
|
}
|
|
2531
2553
|
function remove(obj, key) {
|
|
@@ -2545,7 +2567,8 @@ function remove(obj, key) {
|
|
|
2545
2567
|
obj.splice(key, 1);
|
|
2546
2568
|
}
|
|
2547
2569
|
else {
|
|
2548
|
-
return fail(
|
|
2570
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2571
|
+
"'remove()' can only be used on observable objects, arrays and maps");
|
|
2549
2572
|
}
|
|
2550
2573
|
}
|
|
2551
2574
|
function has(obj, key) {
|
|
@@ -2565,7 +2588,8 @@ function has(obj, key) {
|
|
|
2565
2588
|
return key >= 0 && key < obj.length;
|
|
2566
2589
|
}
|
|
2567
2590
|
else {
|
|
2568
|
-
return fail(
|
|
2591
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2592
|
+
"'has()' can only be used on observable objects, arrays and maps");
|
|
2569
2593
|
}
|
|
2570
2594
|
}
|
|
2571
2595
|
function get(obj, key) {
|
|
@@ -2581,7 +2605,8 @@ function get(obj, key) {
|
|
|
2581
2605
|
return obj[key];
|
|
2582
2606
|
}
|
|
2583
2607
|
else {
|
|
2584
|
-
return fail(
|
|
2608
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2609
|
+
"'get()' can only be used on observable objects, arrays and maps");
|
|
2585
2610
|
}
|
|
2586
2611
|
}
|
|
2587
2612
|
|
|
@@ -2697,7 +2722,8 @@ function trace(...args) {
|
|
|
2697
2722
|
enterBreakPoint = args.pop();
|
|
2698
2723
|
const derivation = getAtomFromArgs(args);
|
|
2699
2724
|
if (!derivation) {
|
|
2700
|
-
return fail(
|
|
2725
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2726
|
+
`'trace(break?)' can only be used inside a tracked computed value or a Reaction. Consider passing in the computed value or reaction explicitly`);
|
|
2701
2727
|
}
|
|
2702
2728
|
if (derivation.isTracing === TraceMode.NONE) {
|
|
2703
2729
|
console.log(`[mobx.trace] '${derivation.name}' tracing enabled`);
|
|
@@ -2764,7 +2790,7 @@ function _when(predicate, effect, opts) {
|
|
|
2764
2790
|
return disposer;
|
|
2765
2791
|
}
|
|
2766
2792
|
function whenPromise(predicate, opts) {
|
|
2767
|
-
if (opts && opts.onError)
|
|
2793
|
+
if (process.env.NODE_ENV !== "production" && opts && opts.onError)
|
|
2768
2794
|
return fail(`the options 'onError' and 'promise' cannot be combined`);
|
|
2769
2795
|
let cancel;
|
|
2770
2796
|
const res = new Promise((resolve, reject) => {
|
|
@@ -3641,7 +3667,8 @@ class ObservableMap {
|
|
|
3641
3667
|
* for callback details
|
|
3642
3668
|
*/
|
|
3643
3669
|
observe(listener, fireImmediately) {
|
|
3644
|
-
|
|
3670
|
+
process.env.NODE_ENV !== "production" &&
|
|
3671
|
+
invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with maps.");
|
|
3645
3672
|
return registerListener(this, listener);
|
|
3646
3673
|
}
|
|
3647
3674
|
intercept(handler) {
|
|
@@ -3727,11 +3754,11 @@ class ObservableSet {
|
|
|
3727
3754
|
newValue: value
|
|
3728
3755
|
}
|
|
3729
3756
|
: null;
|
|
3730
|
-
if (notifySpy &&
|
|
3757
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3731
3758
|
spyReportStart(change);
|
|
3732
3759
|
if (notify)
|
|
3733
3760
|
notifyListeners(this, change);
|
|
3734
|
-
if (notifySpy &&
|
|
3761
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3735
3762
|
spyReportEnd();
|
|
3736
3763
|
}
|
|
3737
3764
|
return this;
|
|
@@ -3756,7 +3783,7 @@ class ObservableSet {
|
|
|
3756
3783
|
oldValue: value
|
|
3757
3784
|
}
|
|
3758
3785
|
: null;
|
|
3759
|
-
if (notifySpy &&
|
|
3786
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3760
3787
|
spyReportStart(Object.assign(Object.assign({}, change), { name: this.name }));
|
|
3761
3788
|
transaction(() => {
|
|
3762
3789
|
this._atom.reportChanged();
|
|
@@ -3764,7 +3791,7 @@ class ObservableSet {
|
|
|
3764
3791
|
});
|
|
3765
3792
|
if (notify)
|
|
3766
3793
|
notifyListeners(this, change);
|
|
3767
|
-
if (notifySpy &&
|
|
3794
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3768
3795
|
spyReportEnd();
|
|
3769
3796
|
return true;
|
|
3770
3797
|
}
|
|
@@ -3833,7 +3860,8 @@ class ObservableSet {
|
|
|
3833
3860
|
}
|
|
3834
3861
|
observe(listener, fireImmediately) {
|
|
3835
3862
|
// TODO 'fireImmediately' can be true?
|
|
3836
|
-
|
|
3863
|
+
process.env.NODE_ENV !== "production" &&
|
|
3864
|
+
invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
|
|
3837
3865
|
return registerListener(this, listener);
|
|
3838
3866
|
}
|
|
3839
3867
|
intercept(handler) {
|
|
@@ -3860,10 +3888,18 @@ class ObservableObjectAdministration {
|
|
|
3860
3888
|
this.values = {};
|
|
3861
3889
|
}
|
|
3862
3890
|
read(owner, key) {
|
|
3891
|
+
if (process.env.NODE_ENV === "production" && this.target !== owner) {
|
|
3892
|
+
this.illegalAccess(owner, key);
|
|
3893
|
+
if (!this.values[key])
|
|
3894
|
+
return undefined;
|
|
3895
|
+
}
|
|
3863
3896
|
return this.values[key].get();
|
|
3864
3897
|
}
|
|
3865
3898
|
write(owner, key, newValue) {
|
|
3866
3899
|
const instance = this.target;
|
|
3900
|
+
if (process.env.NODE_ENV === "production" && instance !== owner) {
|
|
3901
|
+
this.illegalAccess(owner, key);
|
|
3902
|
+
}
|
|
3867
3903
|
const observable = this.values[key];
|
|
3868
3904
|
if (observable instanceof ComputedValue) {
|
|
3869
3905
|
observable.set(newValue);
|
|
@@ -3973,7 +4009,8 @@ class ObservableObjectAdministration {
|
|
|
3973
4009
|
* for callback details
|
|
3974
4010
|
*/
|
|
3975
4011
|
observe(callback, fireImmediately) {
|
|
3976
|
-
|
|
4012
|
+
process.env.NODE_ENV !== "production" &&
|
|
4013
|
+
invariant(fireImmediately !== true, "`observe` doesn't support the fire immediately property for observable objects.");
|
|
3977
4014
|
return registerListener(this, callback);
|
|
3978
4015
|
}
|
|
3979
4016
|
intercept(handler) {
|
|
@@ -3990,7 +4027,8 @@ function asObservableObject(target, name = "", defaultEnhancer = deepEnhancer) {
|
|
|
3990
4027
|
let adm = target.$mobx;
|
|
3991
4028
|
if (adm)
|
|
3992
4029
|
return adm;
|
|
3993
|
-
|
|
4030
|
+
process.env.NODE_ENV !== "production" &&
|
|
4031
|
+
invariant(Object.isExtensible(target), "Cannot make the designated object observable; it is not extensible");
|
|
3994
4032
|
if (!isPlainObject(target))
|
|
3995
4033
|
name = (target.constructor.name || "ObservableObject") + "@" + getNextId();
|
|
3996
4034
|
if (!name)
|
|
@@ -4098,7 +4136,8 @@ function getAtom(thing, property) {
|
|
|
4098
4136
|
if (typeof thing === "object" && thing !== null) {
|
|
4099
4137
|
if (isObservableArray(thing)) {
|
|
4100
4138
|
if (property !== undefined)
|
|
4101
|
-
fail(
|
|
4139
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
4140
|
+
"It is not possible to get index atoms from arrays");
|
|
4102
4141
|
return thing.$mobx.atom;
|
|
4103
4142
|
}
|
|
4104
4143
|
if (isObservableSet(thing)) {
|
|
@@ -4110,7 +4149,8 @@ function getAtom(thing, property) {
|
|
|
4110
4149
|
return getAtom(anyThing._keys);
|
|
4111
4150
|
const observable = anyThing._data.get(property) || anyThing._hasMap.get(property);
|
|
4112
4151
|
if (!observable)
|
|
4113
|
-
fail(
|
|
4152
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
4153
|
+
`the entry '${property}' does not exist in the observable map '${getDebugName(thing)}'`);
|
|
4114
4154
|
return observable;
|
|
4115
4155
|
}
|
|
4116
4156
|
// Initializers run lazily when transpiling to babel, so make sure they are run...
|
|
@@ -4119,10 +4159,11 @@ function getAtom(thing, property) {
|
|
|
4119
4159
|
thing[property]; // See #1072
|
|
4120
4160
|
if (isObservableObject(thing)) {
|
|
4121
4161
|
if (!property)
|
|
4122
|
-
return fail(`please specify a property`);
|
|
4162
|
+
return fail(process.env.NODE_ENV !== "production" && `please specify a property`);
|
|
4123
4163
|
const observable = thing.$mobx.values[property];
|
|
4124
4164
|
if (!observable)
|
|
4125
|
-
fail(
|
|
4165
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
4166
|
+
`no observable property '${property}' found on the observable object '${getDebugName(thing)}'`);
|
|
4126
4167
|
return observable;
|
|
4127
4168
|
}
|
|
4128
4169
|
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
|
@@ -4135,7 +4176,7 @@ function getAtom(thing, property) {
|
|
|
4135
4176
|
return thing.$mobx;
|
|
4136
4177
|
}
|
|
4137
4178
|
}
|
|
4138
|
-
return fail("Cannot obtain atom from " + thing);
|
|
4179
|
+
return fail(process.env.NODE_ENV !== "production" && "Cannot obtain atom from " + thing);
|
|
4139
4180
|
}
|
|
4140
4181
|
function getAdministration(thing, property) {
|
|
4141
4182
|
if (!thing)
|
|
@@ -4150,7 +4191,7 @@ function getAdministration(thing, property) {
|
|
|
4150
4191
|
initializeInstance(thing);
|
|
4151
4192
|
if (thing.$mobx)
|
|
4152
4193
|
return thing.$mobx;
|
|
4153
|
-
fail("Cannot obtain administration from " + thing);
|
|
4194
|
+
fail(process.env.NODE_ENV !== "production" && "Cannot obtain administration from " + thing);
|
|
4154
4195
|
}
|
|
4155
4196
|
function getDebugName(thing, property) {
|
|
4156
4197
|
let named;
|
|
@@ -4326,6 +4367,11 @@ but at least in this file we can magically reorder the imports with trial and er
|
|
|
4326
4367
|
*
|
|
4327
4368
|
*/
|
|
4328
4369
|
try {
|
|
4370
|
+
// define process.env if needed
|
|
4371
|
+
// if this is not a production build in the first place
|
|
4372
|
+
// (in which case the expression below would be substituted with 'production')
|
|
4373
|
+
// tslint:disable-next-line
|
|
4374
|
+
process.env.NODE_ENV;
|
|
4329
4375
|
}
|
|
4330
4376
|
catch (e) {
|
|
4331
4377
|
const g = getGlobal();
|
|
@@ -4336,8 +4382,8 @@ catch (e) {
|
|
|
4336
4382
|
(() => {
|
|
4337
4383
|
function testCodeMinification() { }
|
|
4338
4384
|
if (testCodeMinification.name !== "testCodeMinification" &&
|
|
4339
|
-
|
|
4340
|
-
process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
|
|
4385
|
+
process.env.NODE_ENV !== "production" &&
|
|
4386
|
+
typeof process !== 'undefined' && process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
|
|
4341
4387
|
// trick so it doesn't get replaced
|
|
4342
4388
|
const varName = ["process", "env", "NODE_ENV"].join(".");
|
|
4343
4389
|
console.warn(`[mobx] you are running a minified build, but '${varName}' was not set to 'production' in your bundler. This results in an unnecessarily large and slow bundle`);
|
|
@@ -4356,7 +4402,8 @@ if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
|
|
|
4356
4402
|
});
|
|
4357
4403
|
}
|
|
4358
4404
|
// TODO: remove in some future build
|
|
4359
|
-
if (
|
|
4405
|
+
if (process.env.NODE_ENV !== "production" &&
|
|
4406
|
+
typeof module !== "undefined" &&
|
|
4360
4407
|
typeof module.exports !== "undefined") {
|
|
4361
4408
|
let warnedAboutDefaultExport = false;
|
|
4362
4409
|
Object.defineProperty(module.exports, "default", {
|
package/lib/mobx.js
CHANGED
|
@@ -4480,7 +4480,7 @@ catch (e) {
|
|
|
4480
4480
|
function testCodeMinification() { }
|
|
4481
4481
|
if (testCodeMinification.name !== "testCodeMinification" &&
|
|
4482
4482
|
"development" !== "production" &&
|
|
4483
|
-
process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
|
|
4483
|
+
typeof process !== 'undefined' && process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
|
|
4484
4484
|
// trick so it doesn't get replaced
|
|
4485
4485
|
var varName = ["process", "env", "NODE_ENV"].join(".");
|
|
4486
4486
|
console.warn("[mobx] you are running a minified build, but '" + varName + "' was not set to 'production' in your bundler. This results in an unnecessarily large and slow bundle");
|