Comparing version 0.5.1 to 0.5.2
217
lib/index.js
@@ -1,112 +0,111 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "./useAsync", "./useDebounceFn", "./useDebounce", "./useThrottleFn", "./useThrottle", "./useMount", "./useUnmount", "./useUpdate", "./useUpdateEffect", "./useUpdateLayoutEffect", "./useClientRect", "./usePrevious", "./usePersistFn"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("./useAsync"), require("./useDebounceFn"), require("./useDebounce"), require("./useThrottleFn"), require("./useThrottle"), require("./useMount"), require("./useUnmount"), require("./useUpdate"), require("./useUpdateEffect"), require("./useUpdateLayoutEffect"), require("./useClientRect"), require("./usePrevious"), require("./usePersistFn")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.useAsync, global.useDebounceFn, global.useDebounce, global.useThrottleFn, global.useThrottle, global.useMount, global.useUnmount, global.useUpdate, global.useUpdateEffect, global.useUpdateLayoutEffect, global.useClientRect, global.usePrevious, global.usePersistFn); | ||
global.rcHooks = mod.exports; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "useAsync", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useAsync["default"]; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _useAsync, _useDebounceFn, _useDebounce, _useThrottleFn, _useThrottle, _useMount, _useUnmount, _useUpdate, _useUpdateEffect, _useUpdateLayoutEffect, _useClientRect, _usePrevious, _usePersistFn) { | ||
"use strict"; | ||
}); | ||
Object.defineProperty(exports, "useDebounceFn", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useDebounceFn["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useDebounce", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useDebounce["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useThrottleFn", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useThrottleFn["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useThrottle", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useThrottle["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useMount", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useMount["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useUnmount", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useUnmount["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useUpdate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useUpdate["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useUpdateEffect", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useUpdateEffect["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useUpdateLayoutEffect", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useUpdateLayoutEffect["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useClientRect", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useClientRect["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "usePrevious", { | ||
enumerable: true, | ||
get: function get() { | ||
return _usePrevious["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "usePersistFn", { | ||
enumerable: true, | ||
get: function get() { | ||
return _usePersistFn["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(_exports, "useAsync", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useAsync["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "useDebounceFn", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useDebounceFn["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "useDebounce", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useDebounce["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "useThrottleFn", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useThrottleFn["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "useThrottle", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useThrottle["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "useMount", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useMount["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "useUnmount", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useUnmount["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "useUpdate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useUpdate["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "useUpdateEffect", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useUpdateEffect["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "useUpdateLayoutEffect", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useUpdateLayoutEffect["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "useClientRect", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useClientRect["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "usePrevious", { | ||
enumerable: true, | ||
get: function get() { | ||
return _usePrevious["default"]; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "usePersistFn", { | ||
enumerable: true, | ||
get: function get() { | ||
return _usePersistFn["default"]; | ||
} | ||
}); | ||
_useAsync = _interopRequireDefault(_useAsync); | ||
_useDebounceFn = _interopRequireDefault(_useDebounceFn); | ||
_useDebounce = _interopRequireDefault(_useDebounce); | ||
_useThrottleFn = _interopRequireDefault(_useThrottleFn); | ||
_useThrottle = _interopRequireDefault(_useThrottle); | ||
_useMount = _interopRequireDefault(_useMount); | ||
_useUnmount = _interopRequireDefault(_useUnmount); | ||
_useUpdate = _interopRequireDefault(_useUpdate); | ||
_useUpdateEffect = _interopRequireDefault(_useUpdateEffect); | ||
_useUpdateLayoutEffect = _interopRequireDefault(_useUpdateLayoutEffect); | ||
_useClientRect = _interopRequireDefault(_useClientRect); | ||
_usePrevious = _interopRequireDefault(_usePrevious); | ||
_usePersistFn = _interopRequireDefault(_usePersistFn); | ||
var _useAsync = _interopRequireDefault(require("./useAsync")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
}); | ||
var _useDebounceFn = _interopRequireDefault(require("./useDebounceFn")); | ||
var _useDebounce = _interopRequireDefault(require("./useDebounce")); | ||
var _useThrottleFn = _interopRequireDefault(require("./useThrottleFn")); | ||
var _useThrottle = _interopRequireDefault(require("./useThrottle")); | ||
var _useMount = _interopRequireDefault(require("./useMount")); | ||
var _useUnmount = _interopRequireDefault(require("./useUnmount")); | ||
var _useUpdate = _interopRequireDefault(require("./useUpdate")); | ||
var _useUpdateEffect = _interopRequireDefault(require("./useUpdateEffect")); | ||
var _useUpdateLayoutEffect = _interopRequireDefault(require("./useUpdateLayoutEffect")); | ||
var _useClientRect = _interopRequireDefault(require("./useClientRect")); | ||
var _usePrevious = _interopRequireDefault(require("./usePrevious")); | ||
var _usePersistFn = _interopRequireDefault(require("./usePersistFn")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
@@ -1,311 +0,310 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react", "lodash.debounce", "lodash.throttle", "../utils", "../utils/cache", "../utils/limit", "../utils/windowFocus", "../utils/windowVisible"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react"), require("lodash.debounce"), require("lodash.throttle"), require("../utils"), require("../utils/cache"), require("../utils/limit"), require("../utils/windowFocus"), require("../utils/windowVisible")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React, global.lodashDebounce, global.lodashThrottle, global.utils, global.utilsCache, global.utilsLimit, global.utilsWindowFocus, global.utilsWindowVisible); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _lodash, _lodash2, _utils, _cache, _limit, _windowFocus, _windowVisible) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
_lodash = _interopRequireDefault(_lodash); | ||
_lodash2 = _interopRequireDefault(_lodash2); | ||
_limit = _interopRequireDefault(_limit); | ||
_windowFocus = _interopRequireDefault(_windowFocus); | ||
_windowVisible = _interopRequireDefault(_windowVisible); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _react = require("react"); | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
var _lodash = _interopRequireDefault(require("lodash.debounce")); | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
var _lodash2 = _interopRequireDefault(require("lodash.throttle")); | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
var _utils = require("../utils"); | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
var _cache = require("../utils/cache"); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
var _limit = _interopRequireDefault(require("../utils/limit")); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var _windowFocus = _interopRequireDefault(require("../utils/windowFocus")); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var _windowVisible = _interopRequireDefault(require("../utils/windowVisible")); | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
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; } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
// TODO: | ||
// 有缓存时,不重新请求,获取缓存时判断params是否相同,长缓存? | ||
// 空函数 | ||
var noop = function noop() {}; // 异步方法hooks | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function useAsync(asyncFn) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$autoRun = _ref.autoRun, | ||
autoRun = _ref$autoRun === void 0 ? true : _ref$autoRun, | ||
_ref$defaultParams = _ref.defaultParams, | ||
defaultParams = _ref$defaultParams === void 0 ? [] : _ref$defaultParams, | ||
_ref$defaultLoading = _ref.defaultLoading, | ||
defaultLoading = _ref$defaultLoading === void 0 ? false : _ref$defaultLoading, | ||
initialData = _ref.initialData, | ||
_ref$cacheKey = _ref.cacheKey, | ||
cacheKey = _ref$cacheKey === void 0 ? '' : _ref$cacheKey, | ||
_ref$cacheTime = _ref.cacheTime, | ||
cacheTime = _ref$cacheTime === void 0 ? 5 * 60 * 1000 : _ref$cacheTime, | ||
_ref$onSuccess = _ref.onSuccess, | ||
onSuccess = _ref$onSuccess === void 0 ? noop : _ref$onSuccess, | ||
_ref$onError = _ref.onError, | ||
onError = _ref$onError === void 0 ? noop : _ref$onError, | ||
_ref$pollingInterval = _ref.pollingInterval, | ||
pollingInterval = _ref$pollingInterval === void 0 ? 0 : _ref$pollingInterval, | ||
_ref$pollingWhenHidde = _ref.pollingWhenHidden, | ||
pollingWhenHidden = _ref$pollingWhenHidde === void 0 ? true : _ref$pollingWhenHidde, | ||
_ref$refreshOnWindowF = _ref.refreshOnWindowFocus, | ||
refreshOnWindowFocus = _ref$refreshOnWindowF === void 0 ? false : _ref$refreshOnWindowF, | ||
_ref$focusTimespan = _ref.focusTimespan, | ||
focusTimespan = _ref$focusTimespan === void 0 ? 5000 : _ref$focusTimespan, | ||
loadingDelay = _ref.loadingDelay, | ||
debounceInterval = _ref.debounceInterval, | ||
throttleInterval = _ref.throttleInterval; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
var _useState = (0, _react.useState)({ | ||
params: [], | ||
loading: !!autoRun || defaultLoading, | ||
error: null, | ||
data: cacheKey ? (0, _cache.getCache)(cacheKey) : initialData | ||
}), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
state = _useState2[0], | ||
set = _useState2[1]; | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
var counterRef = (0, _react.useRef)(0); // 计数器用于判定,或多次执行,只去最后一次结果 | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
var pollingTimerRef = (0, _react.useRef)(null); // 轮询定时器 | ||
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; } | ||
var pollingWhenVisibleFlagRef = (0, _react.useRef)(false); // 视窗获取焦点标识 | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
var loadingDelayTimerRef = (0, _react.useRef)(null); // 延迟loading | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var unmountFlagRef = (0, _react.useRef)(false); // 卸载标识 | ||
// TODO: | ||
// 有缓存时,不重新请求,获取缓存时判断params是否相同,长缓存? | ||
// 空函数 | ||
var noop = function noop() {}; // 异步方法hooks | ||
var unsubscribeRef = (0, _react.useRef)([]); // 取消订阅集合 | ||
var _run = (0, _react.useCallback)(function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
function useAsync(asyncFn) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$autoRun = _ref.autoRun, | ||
autoRun = _ref$autoRun === void 0 ? true : _ref$autoRun, | ||
_ref$defaultParams = _ref.defaultParams, | ||
defaultParams = _ref$defaultParams === void 0 ? [] : _ref$defaultParams, | ||
_ref$defaultLoading = _ref.defaultLoading, | ||
defaultLoading = _ref$defaultLoading === void 0 ? false : _ref$defaultLoading, | ||
initialData = _ref.initialData, | ||
_ref$cacheKey = _ref.cacheKey, | ||
cacheKey = _ref$cacheKey === void 0 ? '' : _ref$cacheKey, | ||
_ref$cacheTime = _ref.cacheTime, | ||
cacheTime = _ref$cacheTime === void 0 ? 5 * 60 * 1000 : _ref$cacheTime, | ||
_ref$onSuccess = _ref.onSuccess, | ||
onSuccess = _ref$onSuccess === void 0 ? noop : _ref$onSuccess, | ||
_ref$onError = _ref.onError, | ||
onError = _ref$onError === void 0 ? noop : _ref$onError, | ||
formatResult = _ref.formatResult, | ||
_ref$pollingInterval = _ref.pollingInterval, | ||
pollingInterval = _ref$pollingInterval === void 0 ? 0 : _ref$pollingInterval, | ||
_ref$pollingWhenHidde = _ref.pollingWhenHidden, | ||
pollingWhenHidden = _ref$pollingWhenHidde === void 0 ? true : _ref$pollingWhenHidde, | ||
_ref$refreshOnWindowF = _ref.refreshOnWindowFocus, | ||
refreshOnWindowFocus = _ref$refreshOnWindowF === void 0 ? false : _ref$refreshOnWindowF, | ||
_ref$focusTimespan = _ref.focusTimespan, | ||
focusTimespan = _ref$focusTimespan === void 0 ? 5000 : _ref$focusTimespan, | ||
loadingDelay = _ref.loadingDelay, | ||
debounceInterval = _ref.debounceInterval, | ||
throttleInterval = _ref.throttleInterval; | ||
// 取消轮询定时器 | ||
if (pollingTimerRef.current) { | ||
clearTimeout(pollingTimerRef.current); | ||
} // 取消延迟loading | ||
var _useState = (0, _react.useState)({ | ||
params: [], | ||
loading: !!autoRun || defaultLoading, | ||
error: null, | ||
data: cacheKey ? (0, _cache.getCache)(cacheKey) : initialData | ||
}), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
state = _useState2[0], | ||
set = _useState2[1]; | ||
var counterRef = (0, _react.useRef)(0); // 计数器用于判定,或多次执行,只去最后一次结果 | ||
if (loadingDelayTimerRef.current) { | ||
clearTimeout(loadingDelayTimerRef.current); | ||
} | ||
var pollingTimerRef = (0, _react.useRef)(null); // 轮询定时器 | ||
counterRef.current += 1; | ||
var currentCount = counterRef.current; // 确保返回最后结果,并且不会返回取消的结果 | ||
var pollingWhenVisibleFlagRef = (0, _react.useRef)(false); // 视窗获取焦点标识 | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
loading: !loadingDelay, | ||
params: args | ||
var loadingDelayTimerRef = (0, _react.useRef)(null); // 延迟loading | ||
var unmountFlagRef = (0, _react.useRef)(false); // 卸载标识 | ||
var unsubscribeRef = (0, _react.useRef)([]); // 取消订阅集合 | ||
var _run = (0, _react.useCallback)(function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
// 取消轮询定时器 | ||
if (pollingTimerRef.current) { | ||
clearTimeout(pollingTimerRef.current); | ||
} // 取消延迟loading | ||
if (loadingDelayTimerRef.current) { | ||
clearTimeout(loadingDelayTimerRef.current); | ||
} | ||
counterRef.current += 1; | ||
var currentCount = counterRef.current; // 确保返回最后结果,并且不会返回取消的结果 | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
loading: !loadingDelay, | ||
params: args | ||
}); | ||
}); // 设置延迟loading定时器 | ||
if (loadingDelay) { | ||
loadingDelayTimerRef.current = setTimeout(function () { | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
loading: true | ||
}); | ||
}); | ||
}); // 设置延迟loading定时器 | ||
}, loadingDelay); | ||
} else { | ||
loadingDelayTimerRef.current = null; | ||
} // fix: 同时多次调用run,并通过then处理时,前面调用的会返回undefined导致异常的问题 | ||
if (loadingDelay) { | ||
loadingDelayTimerRef.current = setTimeout(function () { | ||
return new Promise(function (resolve, reject) { | ||
asyncFn.apply(void 0, args).then(function (data) { | ||
if (!unmountFlagRef.current && currentCount === counterRef.current) { | ||
if (loadingDelayTimerRef.current) { | ||
clearTimeout(loadingDelayTimerRef.current); | ||
} | ||
var fmtData = typeof formatResult === 'function' ? formatResult(data) : data; | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
loading: true | ||
data: fmtData, | ||
error: null, | ||
loading: false | ||
}); | ||
}); | ||
}, loadingDelay); | ||
} else { | ||
loadingDelayTimerRef.current = null; | ||
} // fix: 同时多次调用2次run,并通过then处理时,前面调用的会返回undefined导致异常的问题 | ||
if (cacheKey) { | ||
(0, _cache.setCache)(cacheKey, fmtData, cacheTime); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
asyncFn.apply(void 0, args).then(function (data) { | ||
if (!unmountFlagRef.current && currentCount === counterRef.current) { | ||
if (loadingDelayTimerRef.current) { | ||
clearTimeout(loadingDelayTimerRef.current); | ||
} | ||
onSuccess(fmtData, args); | ||
resolve(fmtData, args); | ||
} | ||
})["catch"](function (error) { | ||
if (!unmountFlagRef.current && currentCount === counterRef.current) { | ||
if (loadingDelayTimerRef.current) { | ||
clearTimeout(loadingDelayTimerRef.current); | ||
} | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
data: data, | ||
error: null, | ||
loading: false | ||
}); | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
error: error, | ||
loading: false | ||
}); | ||
if (cacheKey) { | ||
(0, _cache.setCache)(cacheKey, data, cacheTime); | ||
}); | ||
onError(error, args); | ||
reject(error, args); | ||
} | ||
})["finally"](function () { | ||
if (!unmountFlagRef.current && currentCount === counterRef.current) { | ||
// 轮询 | ||
if (pollingInterval) { | ||
if (!(0, _utils.isDocumentVisible)() && !pollingWhenHidden) { | ||
pollingWhenVisibleFlagRef.current = true; | ||
return; | ||
} | ||
onSuccess(data, args); | ||
resolve(data, args); | ||
pollingTimerRef.current = setTimeout(function () { | ||
run.apply(void 0, args); | ||
}, pollingInterval); | ||
} | ||
})["catch"](function (error) { | ||
if (!unmountFlagRef.current && currentCount === counterRef.current) { | ||
if (loadingDelayTimerRef.current) { | ||
clearTimeout(loadingDelayTimerRef.current); | ||
} | ||
} | ||
}); | ||
}); | ||
}, []); | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
error: error, | ||
loading: false | ||
}); | ||
}); | ||
onError(error, args); | ||
reject(error, args); | ||
} | ||
})["finally"](function () { | ||
if (!unmountFlagRef.current && currentCount === counterRef.current) { | ||
// 轮询 | ||
if (pollingInterval) { | ||
if (!(0, _utils.isDocumentVisible)() && !pollingWhenHidden) { | ||
pollingWhenVisibleFlagRef.current = true; | ||
return; | ||
} | ||
var debounceRunRef = (0, _react.useRef)(debounceInterval ? (0, _lodash["default"])(_run, debounceInterval) : undefined); | ||
var throttleRunRef = (0, _react.useRef)(throttleInterval ? (0, _lodash2["default"])(_run, throttleInterval) : undefined); | ||
var run = (0, _react.useCallback)(function () { | ||
if (debounceRunRef.current) { | ||
debounceRunRef.current.apply(debounceRunRef, arguments); | ||
return Promise.resolve(null); | ||
} | ||
pollingTimerRef.current = setTimeout(function () { | ||
run.apply(void 0, args); | ||
}, pollingInterval); | ||
} | ||
} | ||
}); | ||
}); | ||
}, []); | ||
if (throttleRunRef.current) { | ||
throttleRunRef.current.apply(throttleRunRef, arguments); | ||
return Promise.resolve(null); | ||
} | ||
var debounceRunRef = (0, _react.useRef)(debounceInterval ? (0, _lodash["default"])(_run, debounceInterval) : undefined); | ||
var throttleRunRef = (0, _react.useRef)(throttleInterval ? (0, _lodash2["default"])(_run, throttleInterval) : undefined); | ||
var run = (0, _react.useCallback)(function () { | ||
if (debounceRunRef.current) { | ||
debounceRunRef.current.apply(debounceRunRef, arguments); | ||
return Promise.resolve(null); | ||
} | ||
return _run.apply(void 0, arguments); | ||
}, []); | ||
var refresh = (0, _react.useCallback)(function () { | ||
return run.apply(void 0, _toConsumableArray(state.params)); | ||
}, []); | ||
var rePolling = (0, _react.useCallback)(function () { | ||
if (pollingWhenVisibleFlagRef.current) { | ||
pollingWhenVisibleFlagRef.current = false; | ||
refresh(); | ||
} | ||
}, []); | ||
var cancel = (0, _react.useCallback)(function () { | ||
if (debounceRunRef.current) { | ||
debounceRunRef.current.cancel(); | ||
} | ||
if (throttleRunRef.current) { | ||
throttleRunRef.current.apply(throttleRunRef, arguments); | ||
return Promise.resolve(null); | ||
} | ||
if (throttleRunRef.current) { | ||
throttleRunRef.current.cancel(); | ||
} // 取消轮询定时器 | ||
return _run.apply(void 0, arguments); | ||
}, []); | ||
var refresh = (0, _react.useCallback)(function () { | ||
return run.apply(void 0, _toConsumableArray(state.params)); | ||
}, []); | ||
var rePolling = (0, _react.useCallback)(function () { | ||
if (pollingWhenVisibleFlagRef.current) { | ||
pollingWhenVisibleFlagRef.current = false; | ||
refresh(); | ||
} | ||
}, []); | ||
var cancel = (0, _react.useCallback)(function () { | ||
if (debounceRunRef.current) { | ||
debounceRunRef.current.cancel(); | ||
} | ||
if (throttleRunRef.current) { | ||
throttleRunRef.current.cancel(); | ||
} // 取消轮询定时器 | ||
if (pollingTimerRef.current) { | ||
clearTimeout(pollingTimerRef.current); | ||
} // 取消延迟loading | ||
if (pollingTimerRef.current) { | ||
clearTimeout(pollingTimerRef.current); | ||
} // 取消延迟loading | ||
if (loadingDelayTimerRef.current) { | ||
clearTimeout(loadingDelayTimerRef.current); | ||
} | ||
pollingWhenVisibleFlagRef.current = false; | ||
counterRef.current += 1; | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
loading: false | ||
}); | ||
}); | ||
}, []); // 突变 | ||
if (loadingDelayTimerRef.current) { | ||
clearTimeout(loadingDelayTimerRef.current); | ||
} | ||
pollingWhenVisibleFlagRef.current = false; | ||
counterRef.current += 1; | ||
var mutate = function mutate(newData) { | ||
if (typeof newData === 'function') { | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
loading: false | ||
data: newData(state.data) | ||
}); | ||
}); | ||
}, []); // 突变 | ||
var mutate = function mutate(newData) { | ||
if (typeof newData === 'function') { | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
data: newData(state.data) | ||
}); | ||
} else { | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
data: newData | ||
}); | ||
} else { | ||
set(function (s) { | ||
return _objectSpread({}, s, { | ||
data: newData | ||
}); | ||
}); | ||
} | ||
}; | ||
}); | ||
} | ||
}; | ||
(0, _react.useEffect)(function () { | ||
// 默认自动执行 | ||
if (autoRun) { | ||
// 参数兼容非array的情况 | ||
var _params = Array.isArray(defaultParams) ? defaultParams : [defaultParams]; | ||
(0, _react.useEffect)(function () { | ||
// 默认自动执行 | ||
if (autoRun) { | ||
// 参数兼容非array的情况 | ||
var _params = Array.isArray(defaultParams) ? defaultParams : [defaultParams]; | ||
run.apply(void 0, _toConsumableArray(_params)); | ||
} // 订阅页面显示时轮询 | ||
run.apply(void 0, _toConsumableArray(_params)); | ||
} // 订阅页面显示时轮询 | ||
if (pollingInterval) { | ||
unsubscribeRef.current.push((0, _windowVisible["default"])(rePolling)); | ||
} // 订阅屏幕聚焦时请求 | ||
if (pollingInterval) { | ||
unsubscribeRef.current.push((0, _windowVisible["default"])(rePolling)); | ||
} // 订阅屏幕聚焦时请求 | ||
if (refreshOnWindowFocus) { | ||
var limitRefresh = (0, _limit["default"])(refresh, focusTimespan); | ||
unsubscribeRef.current.push((0, _windowFocus["default"])(limitRefresh)); | ||
} | ||
if (refreshOnWindowFocus) { | ||
var limitRefresh = (0, _limit["default"])(refresh, focusTimespan); | ||
unsubscribeRef.current.push((0, _windowFocus["default"])(limitRefresh)); | ||
} | ||
return function () { | ||
unmountFlagRef.current = true; | ||
cancel(); // 取消订阅 | ||
return function () { | ||
unmountFlagRef.current = true; | ||
cancel(); // 取消订阅 | ||
unsubscribeRef.current.forEach(function (s) { | ||
return s(); | ||
}); | ||
}; | ||
}, []); | ||
return _objectSpread({}, state, { | ||
run: run, | ||
cancel: cancel, | ||
mutate: mutate, | ||
refresh: refresh | ||
}); | ||
} | ||
unsubscribeRef.current.forEach(function (s) { | ||
return s(); | ||
}); | ||
}; | ||
}, []); | ||
return _objectSpread({}, state, { | ||
run: run, | ||
cancel: cancel, | ||
mutate: mutate, | ||
refresh: refresh | ||
}); | ||
} | ||
var _default = useAsync; | ||
_exports["default"] = _default; | ||
}); | ||
var _default = useAsync; | ||
exports["default"] = _default; |
@@ -1,49 +0,37 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
var _react = require("react"); | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
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; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
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; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function useClientRect() { | ||
var _useState = (0, _react.useState)(null), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
rect = _useState2[0], | ||
setRect = _useState2[1]; | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var ref = (0, _react.useCallback)(function (node) { | ||
if (node !== null) { | ||
setRect(node.getBoundingClientRect()); | ||
} | ||
}, []); | ||
return [rect, ref]; | ||
} | ||
function useClientRect() { | ||
var _useState = (0, _react.useState)(null), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
rect = _useState2[0], | ||
setRect = _useState2[1]; | ||
var _default = useClientRect; | ||
_exports["default"] = _default; | ||
}); | ||
var ref = (0, _react.useCallback)(function (node) { | ||
if (node !== null) { | ||
setRect(node.getBoundingClientRect()); | ||
} | ||
}, []); | ||
return [rect, ref]; | ||
} | ||
var _default = useClientRect; | ||
exports["default"] = _default; |
@@ -1,56 +0,45 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react", "../useDebounceFn"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react"), require("../useDebounceFn")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React, global.useDebounceFn); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _useDebounceFn2) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
_useDebounceFn2 = _interopRequireDefault(_useDebounceFn2); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _react = require("react"); | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
var _useDebounceFn2 = _interopRequireDefault(require("../useDebounceFn")); | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
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; } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
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; } | ||
function useDebounce(value) { | ||
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
var _useState = (0, _react.useState)(value), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
state = _useState2[0], | ||
setState = _useState2[1]; | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var _useDebounceFn = (0, _useDebounceFn2["default"])(setState, wait, options), | ||
run = _useDebounceFn.run; | ||
function useDebounce(value) { | ||
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
(0, _react.useEffect)(function () { | ||
run(value); | ||
}, [value]); | ||
return state; | ||
} | ||
var _useState = (0, _react.useState)(value), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
state = _useState2[0], | ||
setState = _useState2[1]; | ||
var _default = useDebounce; | ||
_exports["default"] = _default; | ||
}); | ||
var _useDebounceFn = (0, _useDebounceFn2["default"])(setState, wait, options), | ||
run = _useDebounceFn.run; | ||
(0, _react.useEffect)(function () { | ||
run(value); | ||
}, [value]); | ||
return state; | ||
} | ||
var _default = useDebounce; | ||
exports["default"] = _default; |
@@ -1,42 +0,31 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react", "lodash.debounce"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react"), require("lodash.debounce")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React, global.lodashDebounce); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _lodash) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
_lodash = _interopRequireDefault(_lodash); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _react = require("react"); | ||
var noop = function noop() {}; | ||
var _lodash = _interopRequireDefault(require("lodash.debounce")); | ||
function useDebounceFn() { | ||
var fn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop; | ||
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var debounceRun = (0, _react.useCallback)((0, _lodash["default"])(fn, wait, options), []); | ||
(0, _react.useEffect)(function () { | ||
return debounceRun.cancel; | ||
}, []); | ||
return { | ||
run: debounceRun, | ||
cancel: debounceRun.cancel | ||
}; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _default = useDebounceFn; | ||
_exports["default"] = _default; | ||
}); | ||
var noop = function noop() {}; | ||
function useDebounceFn() { | ||
var fn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop; | ||
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var debounceRun = (0, _react.useCallback)((0, _lodash["default"])(fn, wait, options), []); | ||
(0, _react.useEffect)(function () { | ||
return debounceRun.cancel; | ||
}, []); | ||
return { | ||
run: debounceRun, | ||
cancel: debounceRun.cancel | ||
}; | ||
} | ||
var _default = useDebounceFn; | ||
exports["default"] = _default; |
@@ -1,36 +0,25 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react", "../usePersistFn"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react"), require("../usePersistFn")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React, global.usePersistFn); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _usePersistFn) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
_usePersistFn = _interopRequireDefault(_usePersistFn); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _react = require("react"); | ||
var useMount = function useMount(fn) { | ||
// 持久化函数 | ||
var fnPersist = (0, _usePersistFn["default"])(fn); | ||
(0, _react.useEffect)(function () { | ||
if (fnPersist && typeof fnPersist === 'function') { | ||
fnPersist(); | ||
} | ||
}, []); | ||
}; | ||
var _usePersistFn = _interopRequireDefault(require("../usePersistFn")); | ||
var _default = useMount; | ||
_exports["default"] = _default; | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var useMount = function useMount(fn) { | ||
// 持久化函数 | ||
var fnPersist = (0, _usePersistFn["default"])(fn); | ||
(0, _react.useEffect)(function () { | ||
if (fnPersist && typeof fnPersist === 'function') { | ||
fnPersist(); | ||
} | ||
}, []); | ||
}; | ||
var _default = useMount; | ||
exports["default"] = _default; |
@@ -1,40 +0,28 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
// ref: | ||
// https://zh-hans.reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback | ||
// https://hooks.umijs.org/zh-CN/hooks/advanced/use-persist-fn | ||
var noop = function noop() {}; | ||
var _react = require("react"); | ||
function usePersistFn() { | ||
var fn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop; | ||
var ref = (0, _react.useRef)(function () { | ||
throw new Error('Cannot call function while rendering.'); | ||
}); | ||
ref.current = fn; | ||
return (0, _react.useCallback)(function () { | ||
var fn = ref.current; | ||
return fn(); | ||
}, [ref]); | ||
} | ||
// ref: | ||
// https://zh-hans.reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback | ||
// https://hooks.umijs.org/zh-CN/hooks/advanced/use-persist-fn | ||
var noop = function noop() {}; | ||
var _default = usePersistFn; | ||
_exports["default"] = _default; | ||
}); | ||
function usePersistFn() { | ||
var fn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop; | ||
var ref = (0, _react.useRef)(function () { | ||
throw new Error('Cannot call function while rendering.'); | ||
}); | ||
ref.current = fn; | ||
return (0, _react.useCallback)(function () { | ||
var fn = ref.current; | ||
return fn(); | ||
}, [ref]); | ||
} | ||
var _default = usePersistFn; | ||
exports["default"] = _default; |
@@ -1,30 +0,18 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = usePrevious; | ||
var _react = require("react"); | ||
// ref: | ||
// https://zh-hans.reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state | ||
function usePrevious(value) { | ||
var ref = (0, _react.useRef)(); | ||
(0, _react.useEffect)(function () { | ||
ref.current = value; | ||
}); | ||
_exports["default"] = usePrevious; | ||
// ref: | ||
// https://zh-hans.reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state | ||
function usePrevious(value) { | ||
var ref = (0, _react.useRef)(); | ||
(0, _react.useEffect)(function () { | ||
ref.current = value; | ||
}); | ||
return ref.current; | ||
} | ||
}); | ||
return ref.current; | ||
} |
@@ -1,56 +0,45 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react", "../useThrottleFn"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react"), require("../useThrottleFn")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React, global.useThrottleFn); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _useThrottleFn2) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
_useThrottleFn2 = _interopRequireDefault(_useThrottleFn2); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _react = require("react"); | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
var _useThrottleFn2 = _interopRequireDefault(require("../useThrottleFn")); | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
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; } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
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; } | ||
function useThrottle(value) { | ||
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
var _useState = (0, _react.useState)(value), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
state = _useState2[0], | ||
setState = _useState2[1]; | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var _useThrottleFn = (0, _useThrottleFn2["default"])(setState, wait, options), | ||
run = _useThrottleFn.run; | ||
function useThrottle(value) { | ||
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
(0, _react.useEffect)(function () { | ||
run(value); | ||
}, [value]); | ||
return state; | ||
} | ||
var _useState = (0, _react.useState)(value), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
state = _useState2[0], | ||
setState = _useState2[1]; | ||
var _default = useThrottle; | ||
_exports["default"] = _default; | ||
}); | ||
var _useThrottleFn = (0, _useThrottleFn2["default"])(setState, wait, options), | ||
run = _useThrottleFn.run; | ||
(0, _react.useEffect)(function () { | ||
run(value); | ||
}, [value]); | ||
return state; | ||
} | ||
var _default = useThrottle; | ||
exports["default"] = _default; |
@@ -1,42 +0,31 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react", "lodash.throttle"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react"), require("lodash.throttle")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React, global.lodashThrottle); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _lodash) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
_lodash = _interopRequireDefault(_lodash); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _react = require("react"); | ||
var noop = function noop() {}; | ||
var _lodash = _interopRequireDefault(require("lodash.throttle")); | ||
function useThrottleFn() { | ||
var fn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop; | ||
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var throttleRun = (0, _react.useCallback)((0, _lodash["default"])(fn, wait, options), []); | ||
(0, _react.useEffect)(function () { | ||
return throttleRun.cancel; | ||
}, []); | ||
return { | ||
run: throttleRun, | ||
cancel: throttleRun.cancel | ||
}; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _default = useThrottleFn; | ||
_exports["default"] = _default; | ||
}); | ||
var noop = function noop() {}; | ||
function useThrottleFn() { | ||
var fn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop; | ||
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var throttleRun = (0, _react.useCallback)((0, _lodash["default"])(fn, wait, options), []); | ||
(0, _react.useEffect)(function () { | ||
return throttleRun.cancel; | ||
}, []); | ||
return { | ||
run: throttleRun, | ||
cancel: throttleRun.cancel | ||
}; | ||
} | ||
var _default = useThrottleFn; | ||
exports["default"] = _default; |
@@ -1,35 +0,23 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var useUnmount = function useUnmount(fn) { | ||
var fnRef = (0, _react.useRef)(fn); | ||
fnRef.current = fn; | ||
(0, _react.useEffect)(function () { | ||
return function () { | ||
if (fnRef.current && typeof fnRef.current === 'function') { | ||
fnRef.current(); | ||
} | ||
}; | ||
}, []); | ||
}; | ||
var _react = require("react"); | ||
var _default = useUnmount; | ||
_exports["default"] = _default; | ||
}); | ||
var useUnmount = function useUnmount(fn) { | ||
var fnRef = (0, _react.useRef)(fn); | ||
fnRef.current = fn; | ||
(0, _react.useEffect)(function () { | ||
return function () { | ||
if (fnRef.current && typeof fnRef.current === 'function') { | ||
fnRef.current(); | ||
} | ||
}; | ||
}, []); | ||
}; | ||
var _default = useUnmount; | ||
exports["default"] = _default; |
@@ -1,47 +0,35 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
var _react = require("react"); | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
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; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
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; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
var useUpdate = function useUpdate() { | ||
var _useState = (0, _react.useState)(0), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
setState = _useState2[1]; | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
return (0, _react.useCallback)(function () { | ||
return setState(function (num) { | ||
return num + 1; | ||
}); | ||
}, []); | ||
}; | ||
var useUpdate = function useUpdate() { | ||
var _useState = (0, _react.useState)(0), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
setState = _useState2[1]; | ||
var _default = useUpdate; | ||
_exports["default"] = _default; | ||
}); | ||
return (0, _react.useCallback)(function () { | ||
return setState(function (num) { | ||
return num + 1; | ||
}); | ||
}, []); | ||
}; | ||
var _default = useUpdate; | ||
exports["default"] = _default; |
@@ -1,35 +0,23 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var useUpdateEffect = function useUpdateEffect(effect) { | ||
var deps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var isMounted = (0, _react.useRef)(false); | ||
(0, _react.useEffect)(function () { | ||
if (!isMounted.current) { | ||
isMounted.current = true; | ||
} else { | ||
return effect(); | ||
} | ||
}, deps); | ||
}; | ||
var _react = require("react"); | ||
var _default = useUpdateEffect; | ||
_exports["default"] = _default; | ||
}); | ||
var useUpdateEffect = function useUpdateEffect(effect) { | ||
var deps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var isMounted = (0, _react.useRef)(false); | ||
(0, _react.useEffect)(function () { | ||
if (!isMounted.current) { | ||
isMounted.current = true; | ||
} else { | ||
return effect(); | ||
} | ||
}, deps); | ||
}; | ||
var _default = useUpdateEffect; | ||
exports["default"] = _default; |
@@ -1,35 +0,23 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "react"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("react")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.React); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var useUpdateLayoutEffect = function useUpdateLayoutEffect(effect) { | ||
var deps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var isMounted = (0, _react.useRef)(false); | ||
(0, _react.useLayoutEffect)(function () { | ||
if (!isMounted.current) { | ||
isMounted.current = true; | ||
} else { | ||
return effect(); | ||
} | ||
}, deps); | ||
}; | ||
var _react = require("react"); | ||
var _default = useUpdateLayoutEffect; | ||
_exports["default"] = _default; | ||
}); | ||
var useUpdateLayoutEffect = function useUpdateLayoutEffect(effect) { | ||
var deps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var isMounted = (0, _react.useRef)(false); | ||
(0, _react.useLayoutEffect)(function () { | ||
if (!isMounted.current) { | ||
isMounted.current = true; | ||
} else { | ||
return effect(); | ||
} | ||
}, deps); | ||
}; | ||
var _default = useUpdateLayoutEffect; | ||
exports["default"] = _default; |
@@ -1,46 +0,32 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports); | ||
global.cache = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports.setCache = _exports.getCache = void 0; | ||
var cache = {}; | ||
var defaultCacheTime = 5 * 60 * 1000; // 默认缓存5分钟 | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.setCache = exports.getCache = void 0; | ||
var cache = {}; | ||
var defaultCacheTime = 5 * 60 * 1000; // 默认缓存5分钟 | ||
var getCache = function getCache(key) { | ||
return cache[key] ? cache[key].data : undefined; | ||
}; | ||
var getCache = function getCache(key) { | ||
return cache[key] ? cache[key].data : undefined; | ||
}; | ||
_exports.getCache = getCache; | ||
exports.getCache = getCache; | ||
var setCache = function setCache(key, data) { | ||
var cacheTime = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultCacheTime; | ||
var setCache = function setCache(key, data) { | ||
var cacheTime = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultCacheTime; | ||
if (cache[key]) { | ||
clearTimeout(cache[key].timer); | ||
} | ||
if (cache[key]) { | ||
clearTimeout(cache[key].timer); | ||
} | ||
var timer = setTimeout(function () { | ||
delete cache[key]; | ||
}, cacheTime); | ||
cache[key] = { | ||
data: data, | ||
timer: timer | ||
}; | ||
var timer = setTimeout(function () { | ||
delete cache[key]; | ||
}, cacheTime); | ||
cache[key] = { | ||
data: data, | ||
timer: timer | ||
}; | ||
}; | ||
_exports.setCache = setCache; | ||
}); | ||
exports.setCache = setCache; |
@@ -1,37 +0,23 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports); | ||
global.rcHooks = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports.isDocumentVisible = isDocumentVisible; | ||
_exports.isOnline = isOnline; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.isDocumentVisible = isDocumentVisible; | ||
exports.isOnline = isOnline; | ||
function isDocumentVisible() { | ||
if (typeof document !== 'undefined' && typeof document.visibilityState !== 'undefined') { | ||
return document.visibilityState !== 'hidden'; | ||
} | ||
return true; | ||
function isDocumentVisible() { | ||
if (typeof document !== 'undefined' && typeof document.visibilityState !== 'undefined') { | ||
return document.visibilityState !== 'hidden'; | ||
} | ||
function isOnline() { | ||
if (typeof navigator !== 'undefined' && typeof navigator.onLine !== 'undefined') { | ||
return navigator.onLine; | ||
} | ||
return true; | ||
} | ||
return true; | ||
function isOnline() { | ||
if (typeof navigator !== 'undefined' && typeof navigator.onLine !== 'undefined') { | ||
return navigator.onLine; | ||
} | ||
}); | ||
return true; | ||
} |
@@ -1,32 +0,18 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports); | ||
global.limit = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = limit; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = limit; | ||
function limit(fn, timespan) { | ||
var pending = false; | ||
return function () { | ||
if (pending) return; | ||
pending = true; | ||
fn.apply(void 0, arguments); | ||
setTimeout(function () { | ||
pending = false; | ||
}, timespan); | ||
}; | ||
} | ||
}); | ||
function limit(fn, timespan) { | ||
var pending = false; | ||
return function () { | ||
if (pending) return; | ||
pending = true; | ||
fn.apply(void 0, arguments); | ||
setTimeout(function () { | ||
pending = false; | ||
}, timespan); | ||
}; | ||
} |
@@ -1,94 +0,80 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports); | ||
global.Storage = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var memoryData = {}; | ||
var memoryStorage = { | ||
// eslint-disable-next-line | ||
getItem: function getItem(key) { | ||
return memoryData[key]; | ||
}, | ||
// eslint-disable-next-line | ||
setItem: function setItem(key, data) { | ||
memoryData[key] = data; | ||
}, | ||
// eslint-disable-next-line | ||
removeItem: function removeItem(key) { | ||
var ret = memoryData[key]; | ||
delete memoryData[key]; | ||
return ret; | ||
var memoryData = {}; | ||
var memoryStorage = { | ||
// eslint-disable-next-line | ||
getItem: function getItem(key) { | ||
return memoryData[key]; | ||
}, | ||
// eslint-disable-next-line | ||
setItem: function setItem(key, data) { | ||
memoryData[key] = data; | ||
}, | ||
// eslint-disable-next-line | ||
removeItem: function removeItem(key) { | ||
var ret = memoryData[key]; | ||
delete memoryData[key]; | ||
return ret; | ||
} | ||
}; | ||
var setStorage = function setStorage(storage) { | ||
try { | ||
if (storage.getItem && storage.setItem && storage.removeItem) { | ||
return storage; | ||
} | ||
}; | ||
var setStorage = function setStorage(storage) { | ||
try { | ||
if (storage.getItem && storage.setItem && storage.removeItem) { | ||
return storage; | ||
} | ||
return window.localStorage; | ||
} catch (err) { | ||
// eslint-disable-next-line | ||
console.warn(err); | ||
if (typeof window !== "undefined") { | ||
return window.localStorage; | ||
} catch (err) { | ||
// eslint-disable-next-line | ||
console.warn(err); | ||
if (typeof window !== "undefined") { | ||
return window.localStorage; | ||
} | ||
} | ||
} | ||
return memoryStorage; | ||
}; | ||
return memoryStorage; | ||
}; | ||
var Storage = /*#__PURE__*/function () { | ||
function Storage(key, storage) { | ||
_classCallCheck(this, Storage); | ||
var Storage = /*#__PURE__*/function () { | ||
function Storage(key, storage) { | ||
_classCallCheck(this, Storage); | ||
this.key = key; | ||
this.storage = setStorage(storage); | ||
this.key = key; | ||
this.storage = setStorage(storage); | ||
} | ||
_createClass(Storage, [{ | ||
key: "set", | ||
value: function set(data) { | ||
this.storage.setItem(this.key, JSON.stringify(data)); | ||
} | ||
}, { | ||
key: "get", | ||
value: function get() { | ||
return JSON.parse(this.storage.getItem(this.key)); | ||
} | ||
}, { | ||
key: "remove", | ||
value: function remove() { | ||
this.storage.removeItem(this.key); | ||
} | ||
}]); | ||
_createClass(Storage, [{ | ||
key: "set", | ||
value: function set(data) { | ||
this.storage.setItem(this.key, JSON.stringify(data)); | ||
} | ||
}, { | ||
key: "get", | ||
value: function get() { | ||
return JSON.parse(this.storage.getItem(this.key)); | ||
} | ||
}, { | ||
key: "remove", | ||
value: function remove() { | ||
this.storage.removeItem(this.key); | ||
} | ||
}]); | ||
return Storage; | ||
}(); | ||
return Storage; | ||
}(); | ||
var _default = Storage; | ||
_exports["default"] = _default; | ||
}); | ||
var _default = Storage; | ||
exports["default"] = _default; |
@@ -1,51 +0,40 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "./index"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("./index")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.index); | ||
global.windowFocus = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _index) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
// from swr | ||
var listeners = []; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function subscribe(listener) { | ||
listeners.push(listener); | ||
return function unsubscribe() { | ||
var index = listeners.indexOf(listener); | ||
listeners.splice(index, 1); | ||
}; | ||
} | ||
var _index = require("./index"); | ||
var eventsBinded = false; | ||
// from swr | ||
var listeners = []; | ||
if (typeof window !== 'undefined' && window.addEventListener && !eventsBinded) { | ||
var revalidate = function revalidate() { | ||
if (!(0, _index.isDocumentVisible)() || !(0, _index.isOnline)()) return; | ||
function subscribe(listener) { | ||
listeners.push(listener); | ||
return function unsubscribe() { | ||
var index = listeners.indexOf(listener); | ||
listeners.splice(index, 1); | ||
}; | ||
} | ||
for (var i = 0; i < listeners.length; i++) { | ||
var listener = listeners[i]; | ||
listener(); | ||
} | ||
}; | ||
var eventsBinded = false; | ||
window.addEventListener('visibilitychange', revalidate, false); | ||
window.addEventListener('focus', revalidate, false); // only bind the events once | ||
if (typeof window !== 'undefined' && window.addEventListener && !eventsBinded) { | ||
var revalidate = function revalidate() { | ||
if (!(0, _index.isDocumentVisible)() || !(0, _index.isOnline)()) return; | ||
eventsBinded = true; | ||
} | ||
for (var i = 0; i < listeners.length; i++) { | ||
var listener = listeners[i]; | ||
listener(); | ||
} | ||
}; | ||
var _default = subscribe; | ||
_exports["default"] = _default; | ||
}); | ||
window.addEventListener('visibilitychange', revalidate, false); | ||
window.addEventListener('focus', revalidate, false); // only bind the events once | ||
eventsBinded = true; | ||
} | ||
var _default = subscribe; | ||
exports["default"] = _default; |
@@ -1,50 +0,39 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "./index"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("./index")); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.index); | ||
global.windowVisible = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _index) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports["default"] = void 0; | ||
// from swr | ||
var listeners = []; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function subscribe(listener) { | ||
listeners.push(listener); | ||
return function unsubscribe() { | ||
var index = listeners.indexOf(listener); | ||
listeners.splice(index, 1); | ||
}; | ||
} | ||
var _index = require("./index"); | ||
var eventsBinded = false; | ||
// from swr | ||
var listeners = []; | ||
if (typeof window !== 'undefined' && window.addEventListener && !eventsBinded) { | ||
var revalidate = function revalidate() { | ||
if (!(0, _index.isDocumentVisible)()) return; | ||
function subscribe(listener) { | ||
listeners.push(listener); | ||
return function unsubscribe() { | ||
var index = listeners.indexOf(listener); | ||
listeners.splice(index, 1); | ||
}; | ||
} | ||
for (var i = 0; i < listeners.length; i++) { | ||
var listener = listeners[i]; | ||
listener(); | ||
} | ||
}; | ||
var eventsBinded = false; | ||
window.addEventListener('visibilitychange', revalidate, false); // only bind the events once | ||
if (typeof window !== 'undefined' && window.addEventListener && !eventsBinded) { | ||
var revalidate = function revalidate() { | ||
if (!(0, _index.isDocumentVisible)()) return; | ||
eventsBinded = true; | ||
} | ||
for (var i = 0; i < listeners.length; i++) { | ||
var listener = listeners[i]; | ||
listener(); | ||
} | ||
}; | ||
var _default = subscribe; | ||
_exports["default"] = _default; | ||
}); | ||
window.addEventListener('visibilitychange', revalidate, false); // only bind the events once | ||
eventsBinded = true; | ||
} | ||
var _default = subscribe; | ||
exports["default"] = _default; |
{ | ||
"name": "rc-hooks", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "React Hooks Library.", | ||
@@ -33,3 +33,2 @@ "main": "lib/index.js", | ||
"@babel/core": "^7.9.0", | ||
"@babel/plugin-transform-modules-umd": "^7.9.0", | ||
"@babel/preset-env": "^7.9.0", | ||
@@ -40,2 +39,3 @@ "@babel/preset-react": "^7.9.4", | ||
"dumi": "^1.0.13", | ||
"mockjs": "^1.1.0", | ||
"react": "^16.13.1", | ||
@@ -61,16 +61,4 @@ "react-dom": "^16.13.1" | ||
"@babel/react" | ||
], | ||
"plugins": [ | ||
[ | ||
"@babel/transform-modules-umd", | ||
{ | ||
"globals": { | ||
"react": "React", | ||
"index": "rcHooks" | ||
}, | ||
"exactGlobals": true | ||
} | ||
] | ||
] | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38873
789