@lemon-fe/hooks 1.1.0-alpha.5 → 1.2.0-alpha.1

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/es/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ReactElement } from 'react';
1
+ import React, { type ReactNode, type ReactElement } from 'react';
2
2
  interface Opts<ToastReturnType = any> {
3
3
  showToast: () => ToastReturnType;
4
4
  cancelToast: (toastReturn: ToastReturnType) => void;
@@ -10,5 +10,13 @@ interface Opts<ToastReturnType = any> {
10
10
  requestThrottleInterval: number;
11
11
  }
12
12
  export declare const hooksOpts: Opts;
13
+ /**
14
+ * @description use HookContext
15
+ */
13
16
  export declare function config<ToastReturnType = any>(opts: Partial<Opts<ToastReturnType>>): void;
17
+ export declare const HooksConfigContext: React.Context<Opts<any>>;
18
+ export declare function HooksConfigProvider(props: {
19
+ value: Partial<typeof hooksOpts>;
20
+ children?: ReactNode | null;
21
+ }): JSX.Element;
14
22
  export {};
package/es/config.js CHANGED
@@ -1,3 +1,10 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ import React, { createContext } from 'react';
1
8
  var warning = function warning(name) {
2
9
  console.warn("implement hooks ".concat(name));
3
10
  };
@@ -24,6 +31,16 @@ export var hooksOpts = {
24
31
  },
25
32
  requestThrottleInterval: 0
26
33
  };
34
+
35
+ /**
36
+ * @description use HookContext
37
+ */
27
38
  export function config(opts) {
28
39
  Object.assign(hooksOpts, opts);
40
+ }
41
+ export var HooksConfigContext = /*#__PURE__*/createContext(hooksOpts);
42
+ export function HooksConfigProvider(props) {
43
+ return /*#__PURE__*/React.createElement(HooksConfigContext.Provider, {
44
+ value: _objectSpread(_objectSpread({}, hooksOpts), props.value)
45
+ }, props.children);
29
46
  }
package/es/index.d.ts CHANGED
@@ -7,4 +7,4 @@ export { default as useAsyncEffect } from './use-async-effect';
7
7
  export { default as usePreload } from './use-preload';
8
8
  export { default as useUpdateEffect } from './use-update-effect';
9
9
  export { default as useLastestRef } from './use-latest-ref';
10
- export { config } from './config';
10
+ export { config, HooksConfigContext, HooksConfigProvider } from './config';
package/es/index.js CHANGED
@@ -7,4 +7,4 @@ export { default as useAsyncEffect } from "./use-async-effect";
7
7
  export { default as usePreload } from "./use-preload";
8
8
  export { default as useUpdateEffect } from "./use-update-effect";
9
9
  export { default as useLastestRef } from "./use-latest-ref";
10
- export { config } from "./config";
10
+ export { config, HooksConfigContext, HooksConfigProvider } from "./config";
@@ -8,8 +8,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
8
8
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
- import { useEffect, useState } from 'react';
12
- import { hooksOpts } from "../config";
11
+ import { useContext, useEffect, useState } from 'react';
12
+ import { HooksConfigContext } from "../config";
13
13
  import useRequest from "../use-request";
14
14
  export default function usePreload(opts, deps) {
15
15
  var _useState = useState(null),
@@ -20,6 +20,7 @@ export default function usePreload(opts, deps) {
20
20
  _useState4 = _slicedToArray(_useState3, 2),
21
21
  error = _useState4[0],
22
22
  setError = _useState4[1];
23
+ var hooksOpts = useContext(HooksConfigContext);
23
24
  var request;
24
25
  var _onSuccess;
25
26
  if (typeof opts === 'function') {
@@ -8,8 +8,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
8
8
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
- import { useRef, useEffect, useMemo, useState, useCallback } from 'react';
12
- import { hooksOpts } from "../config";
11
+ import { useRef, useEffect, useMemo, useState, useCallback, useContext } from 'react';
12
+ import { HooksConfigContext } from "../config";
13
13
  import useLastestRef from "../use-latest-ref";
14
14
  import debounce from 'lodash/debounce';
15
15
  import throttle from 'lodash/throttle';
@@ -22,6 +22,7 @@ import throttle from 'lodash/throttle';
22
22
  */
23
23
  export default function useRequest(request) {
24
24
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
25
+ var hooksOpts = useContext(HooksConfigContext);
25
26
  var onSuccess = options.onSuccess,
26
27
  onError = options.onError,
27
28
  _options$throttleInte = options.throttleInterval,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/hooks",
3
- "version": "1.1.0-alpha.5",
3
+ "version": "1.2.0-alpha.1",
4
4
  "description": "> TODO: description",
5
5
  "author": "鲁盛杰 <lusj@cnlemon.net>",
6
6
  "homepage": "",
@@ -30,5 +30,5 @@
30
30
  "antd": "^4.24.8",
31
31
  "react": "^17.0.2"
32
32
  },
33
- "gitHead": "c3c1df5959c399e01220a00e8b277636b98233c6"
33
+ "gitHead": "49675d62b0403af381b58a8a3da02255f2d16dbc"
34
34
  }