extra-react-hooks 0.1.9 → 0.1.10

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.
@@ -32,7 +32,7 @@
32
32
  */
33
33
  /* eslint-disable no-unused-vars */
34
34
  var getOwnPropertySymbols = Object.getOwnPropertySymbols;
35
- var hasOwnProperty = Object.prototype.hasOwnProperty;
35
+ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
36
36
  var propIsEnumerable = Object.prototype.propertyIsEnumerable;
37
37
 
38
38
  function toObject(val) {
@@ -96,7 +96,7 @@
96
96
  from = Object(arguments[s]);
97
97
 
98
98
  for (var key in from) {
99
- if (hasOwnProperty.call(from, key)) {
99
+ if (hasOwnProperty$1.call(from, key)) {
100
100
  to[key] = from[key];
101
101
  }
102
102
  }
@@ -2691,19 +2691,167 @@
2691
2691
 
2692
2692
  var object$1 = {};
2693
2693
 
2694
- object$1.isntEmptyObject = object$1.isEmptyObject = object$1.isRecord = object$1.isntObject = object$1.isObject = void 0;
2694
+ /**
2695
+ * lodash (Custom Build) <https://lodash.com/>
2696
+ * Build: `lodash modularize exports="npm" -o ./`
2697
+ * Copyright jQuery Foundation and other contributors <https://jquery.org/>
2698
+ * Released under MIT license <https://lodash.com/license>
2699
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
2700
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
2701
+ */
2702
+
2703
+ /** `Object#toString` result references. */
2704
+ var objectTag = '[object Object]';
2705
+
2706
+ /**
2707
+ * Checks if `value` is a host object in IE < 9.
2708
+ *
2709
+ * @private
2710
+ * @param {*} value The value to check.
2711
+ * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
2712
+ */
2713
+ function isHostObject(value) {
2714
+ // Many host objects are `Object` objects that can coerce to strings
2715
+ // despite having improperly defined `toString` methods.
2716
+ var result = false;
2717
+ if (value != null && typeof value.toString != 'function') {
2718
+ try {
2719
+ result = !!(value + '');
2720
+ } catch (e) {}
2721
+ }
2722
+ return result;
2723
+ }
2724
+
2725
+ /**
2726
+ * Creates a unary function that invokes `func` with its argument transformed.
2727
+ *
2728
+ * @private
2729
+ * @param {Function} func The function to wrap.
2730
+ * @param {Function} transform The argument transform.
2731
+ * @returns {Function} Returns the new function.
2732
+ */
2733
+ function overArg(func, transform) {
2734
+ return function(arg) {
2735
+ return func(transform(arg));
2736
+ };
2737
+ }
2738
+
2739
+ /** Used for built-in method references. */
2740
+ var funcProto = Function.prototype,
2741
+ objectProto$1 = Object.prototype;
2742
+
2743
+ /** Used to resolve the decompiled source of functions. */
2744
+ var funcToString = funcProto.toString;
2745
+
2746
+ /** Used to check objects for own properties. */
2747
+ var hasOwnProperty = objectProto$1.hasOwnProperty;
2748
+
2749
+ /** Used to infer the `Object` constructor. */
2750
+ var objectCtorString = funcToString.call(Object);
2751
+
2752
+ /**
2753
+ * Used to resolve the
2754
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
2755
+ * of values.
2756
+ */
2757
+ var objectToString = objectProto$1.toString;
2758
+
2759
+ /** Built-in value references. */
2760
+ var getPrototype = overArg(Object.getPrototypeOf, Object);
2761
+
2762
+ /**
2763
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
2764
+ * and has a `typeof` result of "object".
2765
+ *
2766
+ * @static
2767
+ * @memberOf _
2768
+ * @since 4.0.0
2769
+ * @category Lang
2770
+ * @param {*} value The value to check.
2771
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2772
+ * @example
2773
+ *
2774
+ * _.isObjectLike({});
2775
+ * // => true
2776
+ *
2777
+ * _.isObjectLike([1, 2, 3]);
2778
+ * // => true
2779
+ *
2780
+ * _.isObjectLike(_.noop);
2781
+ * // => false
2782
+ *
2783
+ * _.isObjectLike(null);
2784
+ * // => false
2785
+ */
2786
+ function isObjectLike(value) {
2787
+ return !!value && typeof value == 'object';
2788
+ }
2789
+
2790
+ /**
2791
+ * Checks if `value` is a plain object, that is, an object created by the
2792
+ * `Object` constructor or one with a `[[Prototype]]` of `null`.
2793
+ *
2794
+ * @static
2795
+ * @memberOf _
2796
+ * @since 0.8.0
2797
+ * @category Lang
2798
+ * @param {*} value The value to check.
2799
+ * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
2800
+ * @example
2801
+ *
2802
+ * function Foo() {
2803
+ * this.a = 1;
2804
+ * }
2805
+ *
2806
+ * _.isPlainObject(new Foo);
2807
+ * // => false
2808
+ *
2809
+ * _.isPlainObject([1, 2, 3]);
2810
+ * // => false
2811
+ *
2812
+ * _.isPlainObject({ 'x': 0, 'y': 0 });
2813
+ * // => true
2814
+ *
2815
+ * _.isPlainObject(Object.create(null));
2816
+ * // => true
2817
+ */
2818
+ function isPlainObject$1(value) {
2819
+ if (!isObjectLike(value) ||
2820
+ objectToString.call(value) != objectTag || isHostObject(value)) {
2821
+ return false;
2822
+ }
2823
+ var proto = getPrototype(value);
2824
+ if (proto === null) {
2825
+ return true;
2826
+ }
2827
+ var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
2828
+ return (typeof Ctor == 'function' &&
2829
+ Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
2830
+ }
2831
+
2832
+ var lodash_isplainobject = isPlainObject$1;
2833
+
2834
+ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
2835
+ return (mod && mod.__esModule) ? mod : { "default": mod };
2836
+ };object$1.isntEmptyObject = object$1.isEmptyObject = object$1.isntPlainObject = object$1.isPlainObject = object$1.isntObject = object$1.isObject = void 0;
2837
+ const lodash_isplainobject_1 = __importDefault(lodash_isplainobject);
2695
2838
  function isObject$1(val) {
2696
- return val !== null && typeof val === 'object';
2839
+ return val !== null
2840
+ && typeof val === 'object';
2697
2841
  }
2698
2842
  object$1.isObject = isObject$1;
2699
2843
  function isntObject$1(val) {
2700
2844
  return !isObject$1(val);
2701
2845
  }
2702
2846
  object$1.isntObject = isntObject$1;
2703
- function isRecord$1(val) {
2704
- return isObject$1(val);
2847
+ function isPlainObject(val) {
2848
+ return (0, lodash_isplainobject_1.default)(val);
2705
2849
  }
2706
- object$1.isRecord = isRecord$1;
2850
+ object$1.isPlainObject = isPlainObject;
2851
+ function isntPlainObject(val) {
2852
+ return !isPlainObject(val);
2853
+ }
2854
+ object$1.isntPlainObject = isntPlainObject;
2707
2855
  function isEmptyObject$1(val) {
2708
2856
  return Object.keys(val).length === 0;
2709
2857
  }
@@ -2738,7 +2886,7 @@
2738
2886
  return (0, array_1$1.isArray)(val) || (0, object_1$1.isObject)(val);
2739
2887
  }
2740
2888
  function isJsonRpcNotification$1(val) {
2741
- return (0, object_1$1.isRecord)(val)
2889
+ return (0, object_1$1.isPlainObject)(val)
2742
2890
  && (0, string_1$2.isString)(val.jsonrpc)
2743
2891
  && (0, string_1$2.isString)(val.method)
2744
2892
  && (0, undefined_1$3.isUndefined)(val.id)
@@ -2750,7 +2898,7 @@
2750
2898
  }
2751
2899
  jsonRpc$1.isntJsonRpcNotification = isntJsonRpcNotification$1;
2752
2900
  function isJsonRpcRequest$1(val) {
2753
- return (0, object_1$1.isRecord)(val)
2901
+ return (0, object_1$1.isPlainObject)(val)
2754
2902
  && (0, string_1$2.isString)(val.jsonrpc)
2755
2903
  && (0, string_1$2.isString)(val.method)
2756
2904
  && isJsonRpcId$1(val.id)
@@ -2762,7 +2910,7 @@
2762
2910
  }
2763
2911
  jsonRpc$1.isntJsonRpcRequest = isntJsonRpcRequest$1;
2764
2912
  function isJsonRpcSuccess$1(val) {
2765
- return (0, object_1$1.isRecord)(val)
2913
+ return (0, object_1$1.isPlainObject)(val)
2766
2914
  && (0, string_1$2.isString)(val.jsonrpc)
2767
2915
  && (0, string_1$2.isString)(val.id)
2768
2916
  && 'result' in val;
@@ -2773,7 +2921,7 @@
2773
2921
  }
2774
2922
  jsonRpc$1.isntJsonRpcSuccess = isntJsonRpcSuccess$1;
2775
2923
  function isJsonRpcError$1(val) {
2776
- return (0, object_1$1.isRecord)(val)
2924
+ return (0, object_1$1.isPlainObject)(val)
2777
2925
  && (0, string_1$2.isString)(val.jsonrpc)
2778
2926
  && isJsonRpcId$1(val.id)
2779
2927
  && isJsonRpcErrorObject$1(val.error);
@@ -2784,7 +2932,7 @@
2784
2932
  }
2785
2933
  jsonRpc$1.isntJsonRpcError = isntJsonRpcError$1;
2786
2934
  function isJsonRpcErrorObject$1(val) {
2787
- return (0, object_1$1.isRecord)(val)
2935
+ return (0, object_1$1.isPlainObject)(val)
2788
2936
  && (0, number_1$1.isNumber)(val.code)
2789
2937
  && (0, string_1$2.isString)(val.message)
2790
2938
  && ((0, undefined_1$3.isUndefined)(val.data) || (0, object_1$1.isObject)(val.data));
@@ -3011,7 +3159,7 @@
3011
3159
  ];
3012
3160
  }
3013
3161
 
3014
- function useForceUpdate$1() {
3162
+ function useForceUpdate() {
3015
3163
  const [, setState] = react.exports.useState({});
3016
3164
  return () => setState({});
3017
3165
  }
@@ -3533,7 +3681,7 @@
3533
3681
  return (0, object_1.isRecord)(val)
3534
3682
  && (0, string_1.isString)(val.jsonrpc)
3535
3683
  && (0, string_1.isString)(val.id)
3536
- && (0, undefined_1.isntUndefined)(val.result);
3684
+ && 'result' in val;
3537
3685
  }
3538
3686
  jsonRpc.isJsonRpcSuccess = isJsonRpcSuccess;
3539
3687
  function isntJsonRpcSuccess(val) {
@@ -6066,10 +6214,14 @@
6066
6214
  return ar;
6067
6215
  }
6068
6216
 
6069
- function __spreadArray(to, from) {
6070
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
6071
- to[j] = from[i];
6072
- return to;
6217
+ function __spreadArray(to, from, pack) {
6218
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
6219
+ if (ar || !(i in from)) {
6220
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6221
+ ar[i] = from[i];
6222
+ }
6223
+ }
6224
+ return to.concat(ar || Array.prototype.slice.call(from));
6073
6225
  }
6074
6226
 
6075
6227
  function __await(v) {
@@ -6549,16 +6701,20 @@
6549
6701
  var _this = this;
6550
6702
  promiseCtor = getPromiseCtor(promiseCtor);
6551
6703
  return new promiseCtor(function (resolve, reject) {
6552
- var subscription;
6553
- subscription = _this.subscribe(function (value) {
6554
- try {
6555
- next(value);
6556
- }
6557
- catch (err) {
6558
- reject(err);
6559
- subscription === null || subscription === void 0 ? void 0 : subscription.unsubscribe();
6560
- }
6561
- }, reject, resolve);
6704
+ var subscriber = new SafeSubscriber({
6705
+ next: function (value) {
6706
+ try {
6707
+ next(value);
6708
+ }
6709
+ catch (err) {
6710
+ reject(err);
6711
+ subscriber.unsubscribe();
6712
+ }
6713
+ },
6714
+ error: reject,
6715
+ complete: resolve,
6716
+ });
6717
+ _this.subscribe(subscriber);
6562
6718
  });
6563
6719
  };
6564
6720
  Observable.prototype._subscribe = function (subscriber) {
@@ -7270,7 +7426,7 @@
7270
7426
  if ((delay != null && delay > 0) || (delay == null && this.delay > 0)) {
7271
7427
  return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
7272
7428
  }
7273
- if (scheduler.actions.length === 0) {
7429
+ if (!scheduler.actions.some(function (action) { return action.id === id; })) {
7274
7430
  immediateProvider.clearImmediate(id);
7275
7431
  scheduler._scheduled = undefined;
7276
7432
  }
@@ -7334,20 +7490,19 @@
7334
7490
  }
7335
7491
  AsapScheduler.prototype.flush = function (action) {
7336
7492
  this._active = true;
7493
+ var flushId = this._scheduled;
7337
7494
  this._scheduled = undefined;
7338
7495
  var actions = this.actions;
7339
7496
  var error;
7340
- var index = -1;
7341
7497
  action = action || actions.shift();
7342
- var count = actions.length;
7343
7498
  do {
7344
7499
  if ((error = action.execute(action.state, action.delay))) {
7345
7500
  break;
7346
7501
  }
7347
- } while (++index < count && (action = actions.shift()));
7502
+ } while ((action = actions[0]) && action.id === flushId && actions.shift());
7348
7503
  this._active = false;
7349
7504
  if (error) {
7350
- while (++index < count && (action = actions.shift())) {
7505
+ while ((action = actions[0]) && action.id === flushId && actions.shift()) {
7351
7506
  action.unsubscribe();
7352
7507
  }
7353
7508
  throw error;
@@ -7427,7 +7582,7 @@
7427
7582
  if ((delay != null && delay > 0) || (delay == null && this.delay > 0)) {
7428
7583
  return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
7429
7584
  }
7430
- if (scheduler.actions.length === 0) {
7585
+ if (!scheduler.actions.some(function (action) { return action.id === id; })) {
7431
7586
  animationFrameProvider.cancelAnimationFrame(id);
7432
7587
  scheduler._scheduled = undefined;
7433
7588
  }
@@ -7443,20 +7598,19 @@
7443
7598
  }
7444
7599
  AnimationFrameScheduler.prototype.flush = function (action) {
7445
7600
  this._active = true;
7601
+ var flushId = this._scheduled;
7446
7602
  this._scheduled = undefined;
7447
7603
  var actions = this.actions;
7448
7604
  var error;
7449
- var index = -1;
7450
7605
  action = action || actions.shift();
7451
- var count = actions.length;
7452
7606
  do {
7453
7607
  if ((error = action.execute(action.state, action.delay))) {
7454
7608
  break;
7455
7609
  }
7456
- } while (++index < count && (action = actions.shift()));
7610
+ } while ((action = actions[0]) && action.id === flushId && actions.shift());
7457
7611
  this._active = false;
7458
7612
  if (error) {
7459
- while (++index < count && (action = actions.shift())) {
7613
+ while ((action = actions[0]) && action.id === flushId && actions.shift()) {
7460
7614
  action.unsubscribe();
7461
7615
  }
7462
7616
  throw error;
@@ -9816,21 +9970,44 @@
9816
9970
  });
9817
9971
  }
9818
9972
 
9819
- function repeat(count) {
9820
- if (count === void 0) { count = Infinity; }
9973
+ function repeat(countOrConfig) {
9974
+ var _a;
9975
+ var count = Infinity;
9976
+ var delay;
9977
+ if (countOrConfig != null) {
9978
+ if (typeof countOrConfig === 'object') {
9979
+ (_a = countOrConfig.count, count = _a === void 0 ? Infinity : _a, delay = countOrConfig.delay);
9980
+ }
9981
+ else {
9982
+ count = countOrConfig;
9983
+ }
9984
+ }
9821
9985
  return count <= 0
9822
9986
  ? function () { return EMPTY; }
9823
9987
  : operate(function (source, subscriber) {
9824
9988
  var soFar = 0;
9825
- var innerSub;
9826
- var subscribeForRepeat = function () {
9989
+ var sourceSub;
9990
+ var resubscribe = function () {
9991
+ sourceSub === null || sourceSub === void 0 ? void 0 : sourceSub.unsubscribe();
9992
+ sourceSub = null;
9993
+ if (delay != null) {
9994
+ var notifier = typeof delay === 'number' ? timer(delay) : innerFrom(delay(soFar));
9995
+ var notifierSubscriber_1 = new OperatorSubscriber(subscriber, function () {
9996
+ notifierSubscriber_1.unsubscribe();
9997
+ subscribeToSource();
9998
+ });
9999
+ notifier.subscribe(notifierSubscriber_1);
10000
+ }
10001
+ else {
10002
+ subscribeToSource();
10003
+ }
10004
+ };
10005
+ var subscribeToSource = function () {
9827
10006
  var syncUnsub = false;
9828
- innerSub = source.subscribe(new OperatorSubscriber(subscriber, undefined, function () {
10007
+ sourceSub = source.subscribe(new OperatorSubscriber(subscriber, undefined, function () {
9829
10008
  if (++soFar < count) {
9830
- if (innerSub) {
9831
- innerSub.unsubscribe();
9832
- innerSub = null;
9833
- subscribeForRepeat();
10009
+ if (sourceSub) {
10010
+ resubscribe();
9834
10011
  }
9835
10012
  else {
9836
10013
  syncUnsub = true;
@@ -9841,12 +10018,10 @@
9841
10018
  }
9842
10019
  }));
9843
10020
  if (syncUnsub) {
9844
- innerSub.unsubscribe();
9845
- innerSub = null;
9846
- subscribeForRepeat();
10021
+ resubscribe();
9847
10022
  }
9848
10023
  };
9849
- subscribeForRepeat();
10024
+ subscribeToSource();
9850
10025
  });
9851
10026
  }
9852
10027
 
@@ -10328,9 +10503,10 @@
10328
10503
  leading: true,
10329
10504
  trailing: false,
10330
10505
  };
10331
- function throttle(durationSelector, _a) {
10332
- var _b = _a === void 0 ? defaultThrottleConfig : _a, leading = _b.leading, trailing = _b.trailing;
10506
+ function throttle(durationSelector, config) {
10507
+ if (config === void 0) { config = defaultThrottleConfig; }
10333
10508
  return operate(function (source, subscriber) {
10509
+ var leading = config.leading, trailing = config.trailing;
10334
10510
  var hasValue = false;
10335
10511
  var sendValue = null;
10336
10512
  var throttled = null;
@@ -10965,16 +11141,6 @@
10965
11141
  }
10966
11142
  return ref;
10967
11143
  }
10968
- /**
10969
- * Force re-renders Component.
10970
- */
10971
- function useForceUpdate() {
10972
- var updateState = react.exports.useState(0)[1];
10973
- return react.exports.useRef(function () { return updateState(increment); }).current;
10974
- }
10975
- function increment(n) {
10976
- return (n + 1) % 1000000;
10977
- }
10978
11144
  /**
10979
11145
  * Prevent React warning when using useLayoutEffect on server.
10980
11146
  */
@@ -11028,9 +11194,7 @@
11028
11194
  * @param args collected arguments
11029
11195
  */
11030
11196
  function useSubscriptionInternal(useCustomEffect, args) {
11031
- var forceUpdate = useForceUpdate();
11032
11197
  var argsRef = react.exports.useRef(args);
11033
- var errorRef = react.exports.useRef();
11034
11198
  var subscriptionRef = react.exports.useRef();
11035
11199
  // Update the latest observable and callbacks
11036
11200
  // synchronously after render being committed
@@ -11038,7 +11202,6 @@
11038
11202
  argsRef.current = args;
11039
11203
  });
11040
11204
  useCustomEffect(function () {
11041
- errorRef.current = null;
11042
11205
  // keep in closure for checking staleness
11043
11206
  var input$ = argsRef.current[0];
11044
11207
  var subscription = input$.subscribe({
@@ -11063,11 +11226,9 @@
11063
11226
  var errorObserver = ((_a = argsRef.current[1]) === null || _a === void 0 ? void 0 : _a.error) ||
11064
11227
  argsRef.current[2];
11065
11228
  if (errorObserver) {
11066
- errorRef.current = null;
11067
11229
  return errorObserver(error);
11068
11230
  }
11069
- errorRef.current = error;
11070
- forceUpdate();
11231
+ console.error(error);
11071
11232
  },
11072
11233
  complete: function () {
11073
11234
  var _a;
@@ -11087,10 +11248,6 @@
11087
11248
  subscription.unsubscribe();
11088
11249
  };
11089
11250
  }, [args[0]]);
11090
- if (errorRef.current) {
11091
- // Let error boundary catch the error
11092
- throw errorRef.current;
11093
- }
11094
11251
  return subscriptionRef;
11095
11252
  }
11096
11253
 
@@ -11104,7 +11261,7 @@
11104
11261
  }
11105
11262
 
11106
11263
  function useFiniteStateMachine(schema, initialState) {
11107
- const forceUpdate = useForceUpdate$1();
11264
+ const forceUpdate = useForceUpdate();
11108
11265
  const fsm = react.exports.useMemo(() => new es2018$5.ObservableFiniteStateMachine(schema, initialState), [schema]);
11109
11266
  useSubscription(useObservable(() => fsm.observeStateChanges(), [fsm]), forceUpdate);
11110
11267
  return fsm;
@@ -11112,7 +11269,7 @@
11112
11269
 
11113
11270
  exports.ObservableFiniteStateMachine = es2018$5.ObservableFiniteStateMachine;
11114
11271
  exports.useFiniteStateMachine = useFiniteStateMachine;
11115
- exports.useForceUpdate = useForceUpdate$1;
11272
+ exports.useForceUpdate = useForceUpdate;
11116
11273
  exports.useIncrement = useIncrement;
11117
11274
  exports.useIsMounted = useIsMounted;
11118
11275
  exports.useMount = useMount;