mobx 5.14.1 → 5.15.2

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/lib/mobx.js CHANGED
@@ -77,7 +77,7 @@ function __spread() {
77
77
  return ar;
78
78
  }
79
79
 
80
- var OBFUSCATED_ERROR = "An invariant failed, however the error is obfuscated because this is an production build.";
80
+ var OBFUSCATED_ERROR = "An invariant failed, however the error is obfuscated because this is a production build.";
81
81
  var EMPTY_ARRAY = [];
82
82
  Object.freeze(EMPTY_ARRAY);
83
83
  var EMPTY_OBJECT = {};
@@ -321,14 +321,27 @@ function createPropertyInitializerDescriptor(prop, enumerable) {
321
321
  }));
322
322
  }
323
323
  function initializeInstance(target) {
324
+ var e_1, _a;
324
325
  if (target[mobxDidRunLazyInitializersSymbol] === true)
325
326
  return;
326
327
  var decorators = target[mobxPendingDecorators];
327
328
  if (decorators) {
328
329
  addHiddenProp(target, mobxDidRunLazyInitializersSymbol, true);
329
- for (var key in decorators) {
330
- var d = decorators[key];
331
- d.propertyCreator(target, d.prop, d.descriptor, d.decoratorTarget, d.decoratorArguments);
330
+ // Build property key array from both strings and symbols
331
+ var keys = __spread(Object.getOwnPropertySymbols(decorators), Object.keys(decorators));
332
+ try {
333
+ for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
334
+ var key = keys_1_1.value;
335
+ var d = decorators[key];
336
+ d.propertyCreator(target, d.prop, d.descriptor, d.decoratorTarget, d.decoratorArguments);
337
+ }
338
+ }
339
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
340
+ finally {
341
+ try {
342
+ if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
343
+ }
344
+ finally { if (e_1) throw e_1.error; }
332
345
  }
333
346
  }
334
347
  }
@@ -371,7 +384,8 @@ function createPropDecorator(propertyInitiallyEnumerable, propertyCreator) {
371
384
  };
372
385
  }
373
386
  function quacksLikeADecorator(args) {
374
- return (((args.length === 2 || args.length === 3) && typeof args[1] === "string") ||
387
+ return (((args.length === 2 || args.length === 3) &&
388
+ (typeof args[1] === "string" || typeof args[1] === "symbol")) ||
375
389
  (args.length === 4 && args[3] === true));
376
390
  }
377
391
 
@@ -488,7 +502,7 @@ function getEnhancerFromOptions(options) {
488
502
  */
489
503
  function createObservable(v, arg2, arg3) {
490
504
  // @observable someProp;
491
- if (typeof arguments[1] === "string") {
505
+ if (typeof arguments[1] === "string" || typeof arguments[1] === "symbol") {
492
506
  return deepDecorator.apply(null, arguments);
493
507
  }
494
508
  // it is an observable already, done
@@ -655,6 +669,8 @@ function shouldCompute(derivation) {
655
669
  case exports.IDerivationState.STALE:
656
670
  return true;
657
671
  case exports.IDerivationState.POSSIBLY_STALE: {
672
+ // state propagation can occur outside of action/reactive context #2195
673
+ var prevAllowStateReads = allowStateReadsStart(true);
658
674
  var prevUntracked = untrackedStart(); // no need for those computeds to be reported, they will be picked up in trackDerivedFunction.
659
675
  var obs = derivation.observing, l = obs.length;
660
676
  for (var i = 0; i < l; i++) {
@@ -670,6 +686,7 @@ function shouldCompute(derivation) {
670
686
  catch (e) {
671
687
  // we are not interested in the value *or* exception at this moment, but if there is one, notify all
672
688
  untrackedEnd(prevUntracked);
689
+ allowStateReadsEnd(prevAllowStateReads);
673
690
  return true;
674
691
  }
675
692
  }
@@ -678,12 +695,14 @@ function shouldCompute(derivation) {
678
695
  // invariantShouldCompute(derivation)
679
696
  if (derivation.dependenciesState === exports.IDerivationState.STALE) {
680
697
  untrackedEnd(prevUntracked);
698
+ allowStateReadsEnd(prevAllowStateReads);
681
699
  return true;
682
700
  }
683
701
  }
684
702
  }
685
703
  changeDependenciesStateTo0(derivation);
686
704
  untrackedEnd(prevUntracked);
705
+ allowStateReadsEnd(prevAllowStateReads);
687
706
  return false;
688
707
  }
689
708
  }
@@ -1132,8 +1151,7 @@ var ComputedValue = /** @class */ (function () {
1132
1151
  this.isComputing = false; // to check for cycles
1133
1152
  this.isRunningSetter = false;
1134
1153
  this.isTracing = TraceMode.NONE;
1135
- if (process.env.NODE_ENV !== "production" && !options.get)
1136
- throw "[mobx] missing option for computed: get";
1154
+ invariant(options.get, "missing option for computed: get");
1137
1155
  this.derivation = options.get;
1138
1156
  this.name = options.name || "ComputedValue@" + getNextId();
1139
1157
  if (options.set)
@@ -1427,6 +1445,19 @@ var MobXGlobals = /** @class */ (function () {
1427
1445
  }
1428
1446
  return MobXGlobals;
1429
1447
  }());
1448
+ var mockGlobal = {};
1449
+ function getGlobal() {
1450
+ if (typeof window !== "undefined") {
1451
+ return window;
1452
+ }
1453
+ if (typeof global !== "undefined") {
1454
+ return global;
1455
+ }
1456
+ if (typeof self !== "undefined") {
1457
+ return self;
1458
+ }
1459
+ return mockGlobal;
1460
+ }
1430
1461
  var canMergeGlobalState = true;
1431
1462
  var isolateCalled = false;
1432
1463
  var globalState = (function () {
@@ -1480,16 +1511,6 @@ function resetGlobalState() {
1480
1511
  globalState[key] = defaultGlobals[key];
1481
1512
  globalState.allowStateChanges = !globalState.enforceActions;
1482
1513
  }
1483
- var mockGlobal = {};
1484
- function getGlobal() {
1485
- if (typeof window !== "undefined") {
1486
- return window;
1487
- }
1488
- if (typeof global !== "undefined") {
1489
- return global;
1490
- }
1491
- return mockGlobal;
1492
- }
1493
1514
 
1494
1515
  function hasObservers(observable) {
1495
1516
  return observable.observers && observable.observers.size > 0;
@@ -1895,7 +1916,7 @@ function spyReport(event) {
1895
1916
  function spyReportStart(event) {
1896
1917
  if (process.env.NODE_ENV === "production")
1897
1918
  return;
1898
- var change = __assign({}, event, { spyReportStart: true });
1919
+ var change = __assign(__assign({}, event), { spyReportStart: true });
1899
1920
  spyReport(change);
1900
1921
  }
1901
1922
  var END_EVENT = { spyReportEnd: true };
@@ -1903,7 +1924,7 @@ function spyReportEnd(change) {
1903
1924
  if (process.env.NODE_ENV === "production")
1904
1925
  return;
1905
1926
  if (change)
1906
- spyReport(__assign({}, change, { spyReportEnd: true }));
1927
+ spyReport(__assign(__assign({}, change), { spyReportEnd: true }));
1907
1928
  else
1908
1929
  spyReport(END_EVENT);
1909
1930
  }
@@ -2298,8 +2319,6 @@ function extendObservableObjectWithProperties(target, properties, decorators, de
2298
2319
  if (process.env.NODE_ENV !== "production") {
2299
2320
  if (!isPlainObject(properties))
2300
2321
  fail("'extendObservabe' only accepts plain objects as second argument");
2301
- if (Object.getOwnPropertyDescriptor(target, key))
2302
- fail("'extendObservable' can only be used to introduce new properties. Use 'set' or 'decorate' instead. The property '" + stringifyKey(key) + "' already exists on '" + target + "'");
2303
2322
  if (isComputed(descriptor.value))
2304
2323
  fail("Passing a 'computed' as initial property value is no longer supported by extendObservable. Use a getter or decorator instead");
2305
2324
  }
@@ -2353,9 +2372,16 @@ function nodeToObserverTree(node) {
2353
2372
  }
2354
2373
 
2355
2374
  var generatorId = 0;
2375
+ function FlowCancellationError() {
2376
+ this.message = "FLOW_CANCELLED";
2377
+ }
2378
+ FlowCancellationError.prototype = Object.create(Error.prototype);
2379
+ function isFlowCancellationError(error) {
2380
+ return error instanceof FlowCancellationError;
2381
+ }
2356
2382
  function flow(generator) {
2357
2383
  if (arguments.length !== 1)
2358
- fail(!!process.env.NODE_ENV && "Flow expects one 1 argument and cannot be used as decorator");
2384
+ fail(!!process.env.NODE_ENV && "Flow expects 1 argument and cannot be used as decorator");
2359
2385
  var name = generator.name || "<unnamed flow>";
2360
2386
  // Implementation based on https://github.com/tj/co/blob/master/index.js
2361
2387
  return function () {
@@ -2408,13 +2434,13 @@ function flow(generator) {
2408
2434
  if (pendingPromise)
2409
2435
  cancelPromise(pendingPromise);
2410
2436
  // Finally block can return (or yield) stuff..
2411
- var res = gen.return();
2437
+ var res = gen.return(undefined);
2412
2438
  // eat anything that promise would do, it's cancelled!
2413
2439
  var yieldedPromise = Promise.resolve(res.value);
2414
2440
  yieldedPromise.then(noop, noop);
2415
2441
  cancelPromise(yieldedPromise); // maybe it can be cancelled :)
2416
2442
  // reject our original promise
2417
- rejector(new Error("FLOW_CANCELLED"));
2443
+ rejector(new FlowCancellationError());
2418
2444
  }
2419
2445
  catch (e) {
2420
2446
  rejector(e); // there could be a throwing finally block
@@ -2861,7 +2887,7 @@ function whenPromise(predicate, opts) {
2861
2887
  return fail("the options 'onError' and 'promise' cannot be combined");
2862
2888
  var cancel;
2863
2889
  var res = new Promise(function (resolve, reject) {
2864
- var disposer = _when(predicate, resolve, __assign({}, opts, { onError: reject }));
2890
+ var disposer = _when(predicate, resolve, __assign(__assign({}, opts), { onError: reject }));
2865
2891
  cancel = function () {
2866
2892
  disposer();
2867
2893
  reject("WHEN_CANCELLED");
@@ -3178,7 +3204,7 @@ var ObservableArrayAdministration = /** @class */ (function () {
3178
3204
  // The reason why this is on right hand side here (and not above), is this way the uglifier will drop it, but it won't
3179
3205
  // cause any runtime overhead in development mode without NODE_ENV set, unless spying is enabled
3180
3206
  if (notifySpy && process.env.NODE_ENV !== "production")
3181
- spyReportStart(__assign({}, change, { name: this.atom.name }));
3207
+ spyReportStart(__assign(__assign({}, change), { name: this.atom.name }));
3182
3208
  this.atom.reportChanged();
3183
3209
  if (notify)
3184
3210
  notifyListeners(this, change);
@@ -3200,7 +3226,7 @@ var ObservableArrayAdministration = /** @class */ (function () {
3200
3226
  }
3201
3227
  : null;
3202
3228
  if (notifySpy && process.env.NODE_ENV !== "production")
3203
- spyReportStart(__assign({}, change, { name: this.atom.name }));
3229
+ spyReportStart(__assign(__assign({}, change), { name: this.atom.name }));
3204
3230
  this.atom.reportChanged();
3205
3231
  // conform: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe
3206
3232
  if (notify)
@@ -3469,7 +3495,7 @@ var ObservableMap = /** @class */ (function () {
3469
3495
  }
3470
3496
  : null;
3471
3497
  if (notifySpy && process.env.NODE_ENV !== "production")
3472
- spyReportStart(__assign({}, change, { name: this.name, key: key }));
3498
+ spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
3473
3499
  transaction(function () {
3474
3500
  _this._keysAtom.reportChanged();
3475
3501
  _this._updateHasMapEntry(key, false);
@@ -3507,7 +3533,7 @@ var ObservableMap = /** @class */ (function () {
3507
3533
  }
3508
3534
  : null;
3509
3535
  if (notifySpy && process.env.NODE_ENV !== "production")
3510
- spyReportStart(__assign({}, change, { name: this.name, key: key }));
3536
+ spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
3511
3537
  observable.setNewValue(newValue);
3512
3538
  if (notify)
3513
3539
  notifyListeners(this, change);
@@ -3536,7 +3562,7 @@ var ObservableMap = /** @class */ (function () {
3536
3562
  }
3537
3563
  : null;
3538
3564
  if (notifySpy && process.env.NODE_ENV !== "production")
3539
- spyReportStart(__assign({}, change, { name: this.name, key: key }));
3565
+ spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
3540
3566
  if (notify)
3541
3567
  notifyListeners(this, change);
3542
3568
  if (notifySpy && process.env.NODE_ENV !== "production")
@@ -3590,17 +3616,17 @@ var ObservableMap = /** @class */ (function () {
3590
3616
  return this.entries();
3591
3617
  };
3592
3618
  ObservableMap.prototype.forEach = function (callback, thisArg) {
3593
- var e_1, _a;
3619
+ var e_1, _b;
3594
3620
  try {
3595
- for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
3596
- var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
3621
+ for (var _c = __values(this), _d = _c.next(); !_d.done; _d = _c.next()) {
3622
+ var _e = __read(_d.value, 2), key = _e[0], value = _e[1];
3597
3623
  callback.call(thisArg, value, key, this);
3598
3624
  }
3599
3625
  }
3600
3626
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
3601
3627
  finally {
3602
3628
  try {
3603
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3629
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
3604
3630
  }
3605
3631
  finally { if (e_1) throw e_1.error; }
3606
3632
  }
@@ -3615,8 +3641,8 @@ var ObservableMap = /** @class */ (function () {
3615
3641
  if (isPlainObject(other))
3616
3642
  getPlainObjectKeys(other).forEach(function (key) { return _this.set(key, other[key]); });
3617
3643
  else if (Array.isArray(other))
3618
- other.forEach(function (_a) {
3619
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
3644
+ other.forEach(function (_b) {
3645
+ var _c = __read(_b, 2), key = _c[0], value = _c[1];
3620
3646
  return _this.set(key, value);
3621
3647
  });
3622
3648
  else if (isES6Map(other)) {
@@ -3633,17 +3659,17 @@ var ObservableMap = /** @class */ (function () {
3633
3659
  var _this = this;
3634
3660
  transaction(function () {
3635
3661
  untracked(function () {
3636
- var e_2, _a;
3662
+ var e_2, _b;
3637
3663
  try {
3638
- for (var _b = __values(_this.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
3639
- var key = _c.value;
3664
+ for (var _c = __values(_this.keys()), _d = _c.next(); !_d.done; _d = _c.next()) {
3665
+ var key = _d.value;
3640
3666
  _this.delete(key);
3641
3667
  }
3642
3668
  }
3643
3669
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
3644
3670
  finally {
3645
3671
  try {
3646
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3672
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
3647
3673
  }
3648
3674
  finally { if (e_2) throw e_2.error; }
3649
3675
  }
@@ -3678,11 +3704,11 @@ var ObservableMap = /** @class */ (function () {
3678
3704
  * If there are duplicating keys after converting them to strings, behaviour is undetermined.
3679
3705
  */
3680
3706
  ObservableMap.prototype.toPOJO = function () {
3681
- var e_3, _a;
3707
+ var e_3, _b;
3682
3708
  var res = {};
3683
3709
  try {
3684
- for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
3685
- var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
3710
+ for (var _c = __values(this), _d = _c.next(); !_d.done; _d = _c.next()) {
3711
+ var _e = __read(_d.value, 2), key = _e[0], value = _e[1];
3686
3712
  // We lie about symbol key types due to https://github.com/Microsoft/TypeScript/issues/1863
3687
3713
  res[typeof key === "symbol" ? key : stringifyKey(key)] = value;
3688
3714
  }
@@ -3690,7 +3716,7 @@ var ObservableMap = /** @class */ (function () {
3690
3716
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
3691
3717
  finally {
3692
3718
  try {
3693
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3719
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
3694
3720
  }
3695
3721
  finally { if (e_3) throw e_3.error; }
3696
3722
  }
@@ -3763,17 +3789,17 @@ var ObservableSet = /** @class */ (function () {
3763
3789
  var _this = this;
3764
3790
  transaction(function () {
3765
3791
  untracked(function () {
3766
- var e_1, _a;
3792
+ var e_1, _b;
3767
3793
  try {
3768
- for (var _b = __values(_this._data.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
3769
- var value = _c.value;
3794
+ for (var _c = __values(_this._data.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
3795
+ var value = _d.value;
3770
3796
  _this.delete(value);
3771
3797
  }
3772
3798
  }
3773
3799
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
3774
3800
  finally {
3775
3801
  try {
3776
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3802
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
3777
3803
  }
3778
3804
  finally { if (e_1) throw e_1.error; }
3779
3805
  }
@@ -3781,17 +3807,17 @@ var ObservableSet = /** @class */ (function () {
3781
3807
  });
3782
3808
  };
3783
3809
  ObservableSet.prototype.forEach = function (callbackFn, thisArg) {
3784
- var e_2, _a;
3810
+ var e_2, _b;
3785
3811
  try {
3786
- for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
3787
- var value = _c.value;
3812
+ for (var _c = __values(this), _d = _c.next(); !_d.done; _d = _c.next()) {
3813
+ var value = _d.value;
3788
3814
  callbackFn.call(thisArg, value, value, this);
3789
3815
  }
3790
3816
  }
3791
3817
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
3792
3818
  finally {
3793
3819
  try {
3794
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3820
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
3795
3821
  }
3796
3822
  finally { if (e_2) throw e_2.error; }
3797
3823
  }
@@ -3863,7 +3889,7 @@ var ObservableSet = /** @class */ (function () {
3863
3889
  }
3864
3890
  : null;
3865
3891
  if (notifySpy && process.env.NODE_ENV !== "production")
3866
- spyReportStart(__assign({}, change, { name: this.name }));
3892
+ spyReportStart(__assign(__assign({}, change), { name: this.name }));
3867
3893
  transaction(function () {
3868
3894
  _this._atom.reportChanged();
3869
3895
  _this._data.delete(value);
@@ -3998,7 +4024,7 @@ var ObservableObjectAdministration = /** @class */ (function () {
3998
4024
  }
3999
4025
  : null;
4000
4026
  if (notifySpy && process.env.NODE_ENV !== "production")
4001
- spyReportStart(__assign({}, change, { name: this.name, key: key }));
4027
+ spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
4002
4028
  observable.setNewValue(newValue);
4003
4029
  if (notify)
4004
4030
  notifyListeners(this, change);
@@ -4088,7 +4114,7 @@ var ObservableObjectAdministration = /** @class */ (function () {
4088
4114
  }
4089
4115
  : null;
4090
4116
  if (notifySpy && process.env.NODE_ENV !== "production")
4091
- spyReportStart(__assign({}, change, { name: this.name, key: key }));
4117
+ spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
4092
4118
  if (notify)
4093
4119
  notifyListeners(this, change);
4094
4120
  if (notifySpy && process.env.NODE_ENV !== "production")
@@ -4145,7 +4171,7 @@ var ObservableObjectAdministration = /** @class */ (function () {
4145
4171
  }
4146
4172
  : null;
4147
4173
  if (notifySpy && process.env.NODE_ENV !== "production")
4148
- spyReportStart(__assign({}, change, { name: this.name, key: key }));
4174
+ spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
4149
4175
  if (notify)
4150
4176
  notifyListeners(this, change);
4151
4177
  if (notifySpy && process.env.NODE_ENV !== "production")
@@ -4337,9 +4363,6 @@ function eq(a, b, depth, aStack, bStack) {
4337
4363
  var type = typeof a;
4338
4364
  if (type !== "function" && type !== "object" && typeof b != "object")
4339
4365
  return false;
4340
- // Unwrap any wrapped objects.
4341
- a = unwrap(a);
4342
- b = unwrap(b);
4343
4366
  // Compare `[[Class]]` names.
4344
4367
  var className = toString.call(a);
4345
4368
  if (className !== toString.call(b))
@@ -4367,7 +4390,18 @@ function eq(a, b, depth, aStack, bStack) {
4367
4390
  return +a === +b;
4368
4391
  case "[object Symbol]":
4369
4392
  return (typeof Symbol !== "undefined" && Symbol.valueOf.call(a) === Symbol.valueOf.call(b));
4393
+ case "[object Map]":
4394
+ case "[object Set]":
4395
+ // Maps and Sets are unwrapped to arrays of entry-pairs, adding an incidental level.
4396
+ // Hide this extra level by increasing the depth.
4397
+ if (depth >= 0) {
4398
+ depth++;
4399
+ }
4400
+ break;
4370
4401
  }
4402
+ // Unwrap any wrapped objects.
4403
+ a = unwrap(a);
4404
+ b = unwrap(b);
4371
4405
  var areArrays = className === "[object Array]";
4372
4406
  if (!areArrays) {
4373
4407
  if (typeof a != "object" || typeof b != "object")
@@ -4521,11 +4555,14 @@ if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
4521
4555
  }
4522
4556
 
4523
4557
  exports.$mobx = $mobx;
4558
+ exports.FlowCancellationError = FlowCancellationError;
4524
4559
  exports.ObservableMap = ObservableMap;
4525
4560
  exports.ObservableSet = ObservableSet;
4526
4561
  exports.Reaction = Reaction;
4527
4562
  exports._allowStateChanges = allowStateChanges;
4528
4563
  exports._allowStateChangesInsideComputed = allowStateChangesInsideComputed;
4564
+ exports._allowStateReadsEnd = allowStateReadsEnd;
4565
+ exports._allowStateReadsStart = allowStateReadsStart;
4529
4566
  exports._endAction = _endAction;
4530
4567
  exports._getAdministration = getAdministration;
4531
4568
  exports._getGlobalState = getGlobalState;
@@ -4555,6 +4592,7 @@ exports.isArrayLike = isArrayLike;
4555
4592
  exports.isBoxedObservable = isObservableValue;
4556
4593
  exports.isComputed = isComputed;
4557
4594
  exports.isComputedProp = isComputedProp;
4595
+ exports.isFlowCancellationError = isFlowCancellationError;
4558
4596
  exports.isObservable = isObservable;
4559
4597
  exports.isObservableArray = isObservableArray;
4560
4598
  exports.isObservableMap = isObservableMap;
package/lib/mobx.js.flow CHANGED
@@ -475,11 +475,62 @@ declare export function createAtom(
475
475
 
476
476
  declare export function decorate<T>(target: T, decorators: any): T
477
477
 
478
- declare export function flow<T>(fn: (...args: any[]) => T): (...args: any[]) => Promise<T>
478
+ export type CancellablePromise<T> = Promise<T> & { cancel: () => void }
479
+
479
480
  declare export function flow<T>(
480
- name: string,
481
- fn: (...args: any[]) => T
482
- ): (...args: any[]) => Promise<T>
481
+ fn: () => Generator<any, T | Promise<T>, any> | AsyncGenerator<any, T | Promise<T>, any>
482
+ ): () => CancellablePromise<T>
483
+ declare export function flow<T, A>(
484
+ fn: (A) => Generator<any, T | Promise<T>, any> | AsyncGenerator<any, T | Promise<T>, any>
485
+ ): A => CancellablePromise<T>
486
+ declare export function flow<T, A, B>(
487
+ fn: (A, B) => Generator<any, T | Promise<T>, any> | AsyncGenerator<any, T | Promise<T>, any>
488
+ ): (A, B) => CancellablePromise<T>
489
+ declare export function flow<T, A, B, C>(
490
+ fn: (A, B, C) => Generator<any, T | Promise<T>, any> | AsyncGenerator<any, T | Promise<T>, any>
491
+ ): (A, B, C) => CancellablePromise<T>
492
+ declare export function flow<T, A, B, C, D>(
493
+ fn: (
494
+ A,
495
+ B,
496
+ C,
497
+ D
498
+ ) => Generator<any, T | Promise<T>, any> | AsyncGenerator<any, T | Promise<T>, any>
499
+ ): (A, B, C, D) => CancellablePromise<T>
500
+ declare export function flow<T, A, B, C, D, E>(
501
+ fn: (
502
+ A,
503
+ B,
504
+ C,
505
+ D,
506
+ E
507
+ ) => Generator<any, T | Promise<T>, any> | AsyncGenerator<any, T | Promise<T>, any>
508
+ ): (A, B, C, D, E) => CancellablePromise<T>
509
+ declare export function flow<T, A, B, C, D, E, F>(
510
+ fn: (
511
+ A,
512
+ B,
513
+ C,
514
+ D,
515
+ E,
516
+ F
517
+ ) => Generator<any, T | Promise<T>, any> | AsyncGenerator<any, T | Promise<T>, any>
518
+ ): (A, B, C, D, E, F) => CancellablePromise<T>
519
+ declare export function flow<T, A, B, C, D, E, F, G, H>(
520
+ fn: (
521
+ A,
522
+ B,
523
+ C,
524
+ D,
525
+ E,
526
+ F,
527
+ G,
528
+ H
529
+ ) => Generator<any, T | Promise<T>, any> | AsyncGenerator<any, T | Promise<T>, any>
530
+ ): (A, B, C, D, E, F, G, H) => CancellablePromise<T>
531
+
532
+ declare export function isFlowCancellationError(error: Error): boolean
533
+ declare export class FlowCancellationError extends Error {}
483
534
 
484
535
  declare export function keys<K>(map: ObservableMap<K, any>): K[]
485
536
  declare export function keys(obj: any): string[]