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.
@@ -26,7 +26,7 @@ object-assign
26
26
  */
27
27
  /* eslint-disable no-unused-vars */
28
28
  var getOwnPropertySymbols = Object.getOwnPropertySymbols;
29
- var hasOwnProperty = Object.prototype.hasOwnProperty;
29
+ var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
30
30
  var propIsEnumerable = Object.prototype.propertyIsEnumerable;
31
31
 
32
32
  function toObject(val) {
@@ -90,7 +90,7 @@ var objectAssign = shouldUseNative() ? Object.assign : function (target, source)
90
90
  from = Object(arguments[s]);
91
91
 
92
92
  for (var key in from) {
93
- if (hasOwnProperty.call(from, key)) {
93
+ if (hasOwnProperty$1.call(from, key)) {
94
94
  to[key] = from[key];
95
95
  }
96
96
  }
@@ -2685,19 +2685,167 @@ var jsonRpc$1 = {};
2685
2685
 
2686
2686
  var object$1 = {};
2687
2687
 
2688
- object$1.isntEmptyObject = object$1.isEmptyObject = object$1.isRecord = object$1.isntObject = object$1.isObject = void 0;
2688
+ /**
2689
+ * lodash (Custom Build) <https://lodash.com/>
2690
+ * Build: `lodash modularize exports="npm" -o ./`
2691
+ * Copyright jQuery Foundation and other contributors <https://jquery.org/>
2692
+ * Released under MIT license <https://lodash.com/license>
2693
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
2694
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
2695
+ */
2696
+
2697
+ /** `Object#toString` result references. */
2698
+ var objectTag = '[object Object]';
2699
+
2700
+ /**
2701
+ * Checks if `value` is a host object in IE < 9.
2702
+ *
2703
+ * @private
2704
+ * @param {*} value The value to check.
2705
+ * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
2706
+ */
2707
+ function isHostObject(value) {
2708
+ // Many host objects are `Object` objects that can coerce to strings
2709
+ // despite having improperly defined `toString` methods.
2710
+ var result = false;
2711
+ if (value != null && typeof value.toString != 'function') {
2712
+ try {
2713
+ result = !!(value + '');
2714
+ } catch (e) {}
2715
+ }
2716
+ return result;
2717
+ }
2718
+
2719
+ /**
2720
+ * Creates a unary function that invokes `func` with its argument transformed.
2721
+ *
2722
+ * @private
2723
+ * @param {Function} func The function to wrap.
2724
+ * @param {Function} transform The argument transform.
2725
+ * @returns {Function} Returns the new function.
2726
+ */
2727
+ function overArg(func, transform) {
2728
+ return function(arg) {
2729
+ return func(transform(arg));
2730
+ };
2731
+ }
2732
+
2733
+ /** Used for built-in method references. */
2734
+ var funcProto = Function.prototype,
2735
+ objectProto$1 = Object.prototype;
2736
+
2737
+ /** Used to resolve the decompiled source of functions. */
2738
+ var funcToString = funcProto.toString;
2739
+
2740
+ /** Used to check objects for own properties. */
2741
+ var hasOwnProperty = objectProto$1.hasOwnProperty;
2742
+
2743
+ /** Used to infer the `Object` constructor. */
2744
+ var objectCtorString = funcToString.call(Object);
2745
+
2746
+ /**
2747
+ * Used to resolve the
2748
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
2749
+ * of values.
2750
+ */
2751
+ var objectToString = objectProto$1.toString;
2752
+
2753
+ /** Built-in value references. */
2754
+ var getPrototype = overArg(Object.getPrototypeOf, Object);
2755
+
2756
+ /**
2757
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
2758
+ * and has a `typeof` result of "object".
2759
+ *
2760
+ * @static
2761
+ * @memberOf _
2762
+ * @since 4.0.0
2763
+ * @category Lang
2764
+ * @param {*} value The value to check.
2765
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2766
+ * @example
2767
+ *
2768
+ * _.isObjectLike({});
2769
+ * // => true
2770
+ *
2771
+ * _.isObjectLike([1, 2, 3]);
2772
+ * // => true
2773
+ *
2774
+ * _.isObjectLike(_.noop);
2775
+ * // => false
2776
+ *
2777
+ * _.isObjectLike(null);
2778
+ * // => false
2779
+ */
2780
+ function isObjectLike(value) {
2781
+ return !!value && typeof value == 'object';
2782
+ }
2783
+
2784
+ /**
2785
+ * Checks if `value` is a plain object, that is, an object created by the
2786
+ * `Object` constructor or one with a `[[Prototype]]` of `null`.
2787
+ *
2788
+ * @static
2789
+ * @memberOf _
2790
+ * @since 0.8.0
2791
+ * @category Lang
2792
+ * @param {*} value The value to check.
2793
+ * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
2794
+ * @example
2795
+ *
2796
+ * function Foo() {
2797
+ * this.a = 1;
2798
+ * }
2799
+ *
2800
+ * _.isPlainObject(new Foo);
2801
+ * // => false
2802
+ *
2803
+ * _.isPlainObject([1, 2, 3]);
2804
+ * // => false
2805
+ *
2806
+ * _.isPlainObject({ 'x': 0, 'y': 0 });
2807
+ * // => true
2808
+ *
2809
+ * _.isPlainObject(Object.create(null));
2810
+ * // => true
2811
+ */
2812
+ function isPlainObject$1(value) {
2813
+ if (!isObjectLike(value) ||
2814
+ objectToString.call(value) != objectTag || isHostObject(value)) {
2815
+ return false;
2816
+ }
2817
+ var proto = getPrototype(value);
2818
+ if (proto === null) {
2819
+ return true;
2820
+ }
2821
+ var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
2822
+ return (typeof Ctor == 'function' &&
2823
+ Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
2824
+ }
2825
+
2826
+ var lodash_isplainobject = isPlainObject$1;
2827
+
2828
+ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
2829
+ return (mod && mod.__esModule) ? mod : { "default": mod };
2830
+ };object$1.isntEmptyObject = object$1.isEmptyObject = object$1.isntPlainObject = object$1.isPlainObject = object$1.isntObject = object$1.isObject = void 0;
2831
+ const lodash_isplainobject_1 = __importDefault(lodash_isplainobject);
2689
2832
  function isObject$1(val) {
2690
- return val !== null && typeof val === 'object';
2833
+ return val !== null
2834
+ && typeof val === 'object';
2691
2835
  }
2692
2836
  object$1.isObject = isObject$1;
2693
2837
  function isntObject$1(val) {
2694
2838
  return !isObject$1(val);
2695
2839
  }
2696
2840
  object$1.isntObject = isntObject$1;
2697
- function isRecord$1(val) {
2698
- return isObject$1(val);
2841
+ function isPlainObject(val) {
2842
+ return (0, lodash_isplainobject_1.default)(val);
2699
2843
  }
2700
- object$1.isRecord = isRecord$1;
2844
+ object$1.isPlainObject = isPlainObject;
2845
+ function isntPlainObject(val) {
2846
+ return !isPlainObject(val);
2847
+ }
2848
+ object$1.isntPlainObject = isntPlainObject;
2701
2849
  function isEmptyObject$1(val) {
2702
2850
  return Object.keys(val).length === 0;
2703
2851
  }
@@ -2732,7 +2880,7 @@ function isJsonRpcParams$1(val) {
2732
2880
  return (0, array_1$1.isArray)(val) || (0, object_1$1.isObject)(val);
2733
2881
  }
2734
2882
  function isJsonRpcNotification$1(val) {
2735
- return (0, object_1$1.isRecord)(val)
2883
+ return (0, object_1$1.isPlainObject)(val)
2736
2884
  && (0, string_1$2.isString)(val.jsonrpc)
2737
2885
  && (0, string_1$2.isString)(val.method)
2738
2886
  && (0, undefined_1$3.isUndefined)(val.id)
@@ -2744,7 +2892,7 @@ function isntJsonRpcNotification$1(val) {
2744
2892
  }
2745
2893
  jsonRpc$1.isntJsonRpcNotification = isntJsonRpcNotification$1;
2746
2894
  function isJsonRpcRequest$1(val) {
2747
- return (0, object_1$1.isRecord)(val)
2895
+ return (0, object_1$1.isPlainObject)(val)
2748
2896
  && (0, string_1$2.isString)(val.jsonrpc)
2749
2897
  && (0, string_1$2.isString)(val.method)
2750
2898
  && isJsonRpcId$1(val.id)
@@ -2756,7 +2904,7 @@ function isntJsonRpcRequest$1(val) {
2756
2904
  }
2757
2905
  jsonRpc$1.isntJsonRpcRequest = isntJsonRpcRequest$1;
2758
2906
  function isJsonRpcSuccess$1(val) {
2759
- return (0, object_1$1.isRecord)(val)
2907
+ return (0, object_1$1.isPlainObject)(val)
2760
2908
  && (0, string_1$2.isString)(val.jsonrpc)
2761
2909
  && (0, string_1$2.isString)(val.id)
2762
2910
  && 'result' in val;
@@ -2767,7 +2915,7 @@ function isntJsonRpcSuccess$1(val) {
2767
2915
  }
2768
2916
  jsonRpc$1.isntJsonRpcSuccess = isntJsonRpcSuccess$1;
2769
2917
  function isJsonRpcError$1(val) {
2770
- return (0, object_1$1.isRecord)(val)
2918
+ return (0, object_1$1.isPlainObject)(val)
2771
2919
  && (0, string_1$2.isString)(val.jsonrpc)
2772
2920
  && isJsonRpcId$1(val.id)
2773
2921
  && isJsonRpcErrorObject$1(val.error);
@@ -2778,7 +2926,7 @@ function isntJsonRpcError$1(val) {
2778
2926
  }
2779
2927
  jsonRpc$1.isntJsonRpcError = isntJsonRpcError$1;
2780
2928
  function isJsonRpcErrorObject$1(val) {
2781
- return (0, object_1$1.isRecord)(val)
2929
+ return (0, object_1$1.isPlainObject)(val)
2782
2930
  && (0, number_1$1.isNumber)(val.code)
2783
2931
  && (0, string_1$2.isString)(val.message)
2784
2932
  && ((0, undefined_1$3.isUndefined)(val.data) || (0, object_1$1.isObject)(val.data));
@@ -3005,7 +3153,7 @@ function useStep(steps, initialStepIndex = 0) {
3005
3153
  ];
3006
3154
  }
3007
3155
 
3008
- function useForceUpdate$1() {
3156
+ function useForceUpdate() {
3009
3157
  const [, setState] = react.exports.useState({});
3010
3158
  return () => setState({});
3011
3159
  }
@@ -3527,7 +3675,7 @@ function isJsonRpcSuccess(val) {
3527
3675
  return (0, object_1.isRecord)(val)
3528
3676
  && (0, string_1.isString)(val.jsonrpc)
3529
3677
  && (0, string_1.isString)(val.id)
3530
- && (0, undefined_1.isntUndefined)(val.result);
3678
+ && 'result' in val;
3531
3679
  }
3532
3680
  jsonRpc.isJsonRpcSuccess = isJsonRpcSuccess;
3533
3681
  function isntJsonRpcSuccess(val) {
@@ -6060,10 +6208,14 @@ function __read(o, n) {
6060
6208
  return ar;
6061
6209
  }
6062
6210
 
6063
- function __spreadArray(to, from) {
6064
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
6065
- to[j] = from[i];
6066
- return to;
6211
+ function __spreadArray(to, from, pack) {
6212
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
6213
+ if (ar || !(i in from)) {
6214
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6215
+ ar[i] = from[i];
6216
+ }
6217
+ }
6218
+ return to.concat(ar || Array.prototype.slice.call(from));
6067
6219
  }
6068
6220
 
6069
6221
  function __await(v) {
@@ -6543,16 +6695,20 @@ var Observable = (function () {
6543
6695
  var _this = this;
6544
6696
  promiseCtor = getPromiseCtor(promiseCtor);
6545
6697
  return new promiseCtor(function (resolve, reject) {
6546
- var subscription;
6547
- subscription = _this.subscribe(function (value) {
6548
- try {
6549
- next(value);
6550
- }
6551
- catch (err) {
6552
- reject(err);
6553
- subscription === null || subscription === void 0 ? void 0 : subscription.unsubscribe();
6554
- }
6555
- }, reject, resolve);
6698
+ var subscriber = new SafeSubscriber({
6699
+ next: function (value) {
6700
+ try {
6701
+ next(value);
6702
+ }
6703
+ catch (err) {
6704
+ reject(err);
6705
+ subscriber.unsubscribe();
6706
+ }
6707
+ },
6708
+ error: reject,
6709
+ complete: resolve,
6710
+ });
6711
+ _this.subscribe(subscriber);
6556
6712
  });
6557
6713
  };
6558
6714
  Observable.prototype._subscribe = function (subscriber) {
@@ -7264,7 +7420,7 @@ var AsapAction = (function (_super) {
7264
7420
  if ((delay != null && delay > 0) || (delay == null && this.delay > 0)) {
7265
7421
  return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
7266
7422
  }
7267
- if (scheduler.actions.length === 0) {
7423
+ if (!scheduler.actions.some(function (action) { return action.id === id; })) {
7268
7424
  immediateProvider.clearImmediate(id);
7269
7425
  scheduler._scheduled = undefined;
7270
7426
  }
@@ -7328,20 +7484,19 @@ var AsapScheduler = (function (_super) {
7328
7484
  }
7329
7485
  AsapScheduler.prototype.flush = function (action) {
7330
7486
  this._active = true;
7487
+ var flushId = this._scheduled;
7331
7488
  this._scheduled = undefined;
7332
7489
  var actions = this.actions;
7333
7490
  var error;
7334
- var index = -1;
7335
7491
  action = action || actions.shift();
7336
- var count = actions.length;
7337
7492
  do {
7338
7493
  if ((error = action.execute(action.state, action.delay))) {
7339
7494
  break;
7340
7495
  }
7341
- } while (++index < count && (action = actions.shift()));
7496
+ } while ((action = actions[0]) && action.id === flushId && actions.shift());
7342
7497
  this._active = false;
7343
7498
  if (error) {
7344
- while (++index < count && (action = actions.shift())) {
7499
+ while ((action = actions[0]) && action.id === flushId && actions.shift()) {
7345
7500
  action.unsubscribe();
7346
7501
  }
7347
7502
  throw error;
@@ -7421,7 +7576,7 @@ var AnimationFrameAction = (function (_super) {
7421
7576
  if ((delay != null && delay > 0) || (delay == null && this.delay > 0)) {
7422
7577
  return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
7423
7578
  }
7424
- if (scheduler.actions.length === 0) {
7579
+ if (!scheduler.actions.some(function (action) { return action.id === id; })) {
7425
7580
  animationFrameProvider.cancelAnimationFrame(id);
7426
7581
  scheduler._scheduled = undefined;
7427
7582
  }
@@ -7437,20 +7592,19 @@ var AnimationFrameScheduler = (function (_super) {
7437
7592
  }
7438
7593
  AnimationFrameScheduler.prototype.flush = function (action) {
7439
7594
  this._active = true;
7595
+ var flushId = this._scheduled;
7440
7596
  this._scheduled = undefined;
7441
7597
  var actions = this.actions;
7442
7598
  var error;
7443
- var index = -1;
7444
7599
  action = action || actions.shift();
7445
- var count = actions.length;
7446
7600
  do {
7447
7601
  if ((error = action.execute(action.state, action.delay))) {
7448
7602
  break;
7449
7603
  }
7450
- } while (++index < count && (action = actions.shift()));
7604
+ } while ((action = actions[0]) && action.id === flushId && actions.shift());
7451
7605
  this._active = false;
7452
7606
  if (error) {
7453
- while (++index < count && (action = actions.shift())) {
7607
+ while ((action = actions[0]) && action.id === flushId && actions.shift()) {
7454
7608
  action.unsubscribe();
7455
7609
  }
7456
7610
  throw error;
@@ -9810,21 +9964,44 @@ function raceWith() {
9810
9964
  });
9811
9965
  }
9812
9966
 
9813
- function repeat(count) {
9814
- if (count === void 0) { count = Infinity; }
9967
+ function repeat(countOrConfig) {
9968
+ var _a;
9969
+ var count = Infinity;
9970
+ var delay;
9971
+ if (countOrConfig != null) {
9972
+ if (typeof countOrConfig === 'object') {
9973
+ (_a = countOrConfig.count, count = _a === void 0 ? Infinity : _a, delay = countOrConfig.delay);
9974
+ }
9975
+ else {
9976
+ count = countOrConfig;
9977
+ }
9978
+ }
9815
9979
  return count <= 0
9816
9980
  ? function () { return EMPTY; }
9817
9981
  : operate(function (source, subscriber) {
9818
9982
  var soFar = 0;
9819
- var innerSub;
9820
- var subscribeForRepeat = function () {
9983
+ var sourceSub;
9984
+ var resubscribe = function () {
9985
+ sourceSub === null || sourceSub === void 0 ? void 0 : sourceSub.unsubscribe();
9986
+ sourceSub = null;
9987
+ if (delay != null) {
9988
+ var notifier = typeof delay === 'number' ? timer(delay) : innerFrom(delay(soFar));
9989
+ var notifierSubscriber_1 = new OperatorSubscriber(subscriber, function () {
9990
+ notifierSubscriber_1.unsubscribe();
9991
+ subscribeToSource();
9992
+ });
9993
+ notifier.subscribe(notifierSubscriber_1);
9994
+ }
9995
+ else {
9996
+ subscribeToSource();
9997
+ }
9998
+ };
9999
+ var subscribeToSource = function () {
9821
10000
  var syncUnsub = false;
9822
- innerSub = source.subscribe(new OperatorSubscriber(subscriber, undefined, function () {
10001
+ sourceSub = source.subscribe(new OperatorSubscriber(subscriber, undefined, function () {
9823
10002
  if (++soFar < count) {
9824
- if (innerSub) {
9825
- innerSub.unsubscribe();
9826
- innerSub = null;
9827
- subscribeForRepeat();
10003
+ if (sourceSub) {
10004
+ resubscribe();
9828
10005
  }
9829
10006
  else {
9830
10007
  syncUnsub = true;
@@ -9835,12 +10012,10 @@ function repeat(count) {
9835
10012
  }
9836
10013
  }));
9837
10014
  if (syncUnsub) {
9838
- innerSub.unsubscribe();
9839
- innerSub = null;
9840
- subscribeForRepeat();
10015
+ resubscribe();
9841
10016
  }
9842
10017
  };
9843
- subscribeForRepeat();
10018
+ subscribeToSource();
9844
10019
  });
9845
10020
  }
9846
10021
 
@@ -10322,9 +10497,10 @@ var defaultThrottleConfig = {
10322
10497
  leading: true,
10323
10498
  trailing: false,
10324
10499
  };
10325
- function throttle(durationSelector, _a) {
10326
- var _b = _a === void 0 ? defaultThrottleConfig : _a, leading = _b.leading, trailing = _b.trailing;
10500
+ function throttle(durationSelector, config) {
10501
+ if (config === void 0) { config = defaultThrottleConfig; }
10327
10502
  return operate(function (source, subscriber) {
10503
+ var leading = config.leading, trailing = config.trailing;
10328
10504
  var hasValue = false;
10329
10505
  var sendValue = null;
10330
10506
  var throttled = null;
@@ -10959,16 +11135,6 @@ function useRefFn(init) {
10959
11135
  }
10960
11136
  return ref;
10961
11137
  }
10962
- /**
10963
- * Force re-renders Component.
10964
- */
10965
- function useForceUpdate() {
10966
- var updateState = react.exports.useState(0)[1];
10967
- return react.exports.useRef(function () { return updateState(increment); }).current;
10968
- }
10969
- function increment(n) {
10970
- return (n + 1) % 1000000;
10971
- }
10972
11138
  /**
10973
11139
  * Prevent React warning when using useLayoutEffect on server.
10974
11140
  */
@@ -11022,9 +11188,7 @@ function useObservable(init, inputs) {
11022
11188
  * @param args collected arguments
11023
11189
  */
11024
11190
  function useSubscriptionInternal(useCustomEffect, args) {
11025
- var forceUpdate = useForceUpdate();
11026
11191
  var argsRef = react.exports.useRef(args);
11027
- var errorRef = react.exports.useRef();
11028
11192
  var subscriptionRef = react.exports.useRef();
11029
11193
  // Update the latest observable and callbacks
11030
11194
  // synchronously after render being committed
@@ -11032,7 +11196,6 @@ function useSubscriptionInternal(useCustomEffect, args) {
11032
11196
  argsRef.current = args;
11033
11197
  });
11034
11198
  useCustomEffect(function () {
11035
- errorRef.current = null;
11036
11199
  // keep in closure for checking staleness
11037
11200
  var input$ = argsRef.current[0];
11038
11201
  var subscription = input$.subscribe({
@@ -11057,11 +11220,9 @@ function useSubscriptionInternal(useCustomEffect, args) {
11057
11220
  var errorObserver = ((_a = argsRef.current[1]) === null || _a === void 0 ? void 0 : _a.error) ||
11058
11221
  argsRef.current[2];
11059
11222
  if (errorObserver) {
11060
- errorRef.current = null;
11061
11223
  return errorObserver(error);
11062
11224
  }
11063
- errorRef.current = error;
11064
- forceUpdate();
11225
+ console.error(error);
11065
11226
  },
11066
11227
  complete: function () {
11067
11228
  var _a;
@@ -11081,10 +11242,6 @@ function useSubscriptionInternal(useCustomEffect, args) {
11081
11242
  subscription.unsubscribe();
11082
11243
  };
11083
11244
  }, [args[0]]);
11084
- if (errorRef.current) {
11085
- // Let error boundary catch the error
11086
- throw errorRef.current;
11087
- }
11088
11245
  return subscriptionRef;
11089
11246
  }
11090
11247
 
@@ -11098,12 +11255,12 @@ function useSubscription(input$, observerOrNext$, error, complete) {
11098
11255
  }
11099
11256
 
11100
11257
  function useFiniteStateMachine(schema, initialState) {
11101
- const forceUpdate = useForceUpdate$1();
11258
+ const forceUpdate = useForceUpdate();
11102
11259
  const fsm = react.exports.useMemo(() => new es2018$5.ObservableFiniteStateMachine(schema, initialState), [schema]);
11103
11260
  useSubscription(useObservable(() => fsm.observeStateChanges(), [fsm]), forceUpdate);
11104
11261
  return fsm;
11105
11262
  }
11106
11263
 
11107
11264
  var ObservableFiniteStateMachine = es2018$5.ObservableFiniteStateMachine;
11108
- export { ObservableFiniteStateMachine, useFiniteStateMachine, useForceUpdate$1 as useForceUpdate, useIncrement, useIsMounted, useMount, useResizeObserver, useSingleSelection, useStateCycle, useStep, useToggle };
11265
+ export { ObservableFiniteStateMachine, useFiniteStateMachine, useForceUpdate, useIncrement, useIsMounted, useMount, useResizeObserver, useSingleSelection, useStateCycle, useStep, useToggle };
11109
11266
  //# sourceMappingURL=index.mjs.map