@entur/utils
Advanced tools
Comparing version 0.9.5 to 1.0.0-beta.0
@@ -1,3 +0,3 @@ | ||
export * from './debounce'; | ||
export * from './PolymorphicComponent'; | ||
export * from './useDebounce'; | ||
export * from './useRandomId'; | ||
@@ -4,0 +4,0 @@ export * from './useOnMount'; |
@@ -8,13 +8,23 @@ 'use strict'; | ||
function debounce(fn, delay) { | ||
var id; | ||
return function () { | ||
function useDebounce(callBack, debounceTime) { | ||
var timeoutRef = React.useRef(); | ||
React.useEffect(function () { | ||
return function () { | ||
if (timeoutRef.current) { | ||
clearTimeout(timeoutRef.current); | ||
} | ||
}; | ||
}, []); | ||
var debouncedFunc = function debouncedFunc() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
clearTimeout(id); | ||
id = setTimeout(function () { | ||
return fn.apply(void 0, args); | ||
}, delay); | ||
if (timeoutRef.current) { | ||
clearTimeout(timeoutRef.current); | ||
} | ||
timeoutRef.current = setTimeout(function () { | ||
callBack.apply(void 0, args); | ||
}, debounceTime); | ||
}; | ||
return debouncedFunc; | ||
} | ||
@@ -184,4 +194,4 @@ | ||
exports.ConditionalWrapper = ConditionalWrapper; | ||
exports.debounce = debounce; | ||
exports.mergeRefs = mergeRefs; | ||
exports.useDebounce = useDebounce; | ||
exports.useForceUpdate = useForceUpdate; | ||
@@ -188,0 +198,0 @@ exports.useOnClickOutside = useOnClickOutside; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");require("tiny-warning");var n=function(){if("undefined"==typeof window)return{width:void 0,height:void 0};var e=window;return{width:e.innerWidth,height:e.innerHeight}};exports.ConditionalWrapper=function(n){var t=n.children;return n.condition?(0,n.wrapper)(t):e.createElement(e.Fragment,null,t)},exports.debounce=function(e,n){var t;return function(){for(var r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];clearTimeout(t),t=setTimeout((function(){return e.apply(void 0,o)}),n)}},exports.mergeRefs=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return function(e){for(var t=0,r=n;t<r.length;t++){var o=r[t];"function"==typeof o?o(e):o&&(o.current=e)}}},exports.useForceUpdate=function(){var n=e.useState(0)[1];return function(){return n((function(e){return e+1}))}},exports.useOnClickOutside=function(n,t){e.useEffect((function(){var e=function(e){n.some((function(n){return function(e,n){return!(!e||!(e.contains(n.target)||n.composed&&n.composedPath&&n.composedPath().find((function(n){return n!==window&&e.contains(n)}))))}(n.current,e)}))||t()};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),function(){document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}}),[n,t])},exports.useOnEscape=function(n,t){e.useEffect((function(){var e=function(e){"Escape"===e.key&&t()},r=n.current;return null==r||r.addEventListener("keydown",e),function(){return null==r?void 0:r.removeEventListener("keydown",e)}}),[n,t])},exports.useOnMount=function(n){var t=e.useRef(!1);e.useEffect((function(){t.current||(t.current=!0,n())}),[n])},exports.useRandomId=function(n){return n+"-"+e.useRef(String(Math.random()).substring(2)).current},exports.useWindowDimensions=function(){var t=e.useState(n()),r=t[0],o=t[1];return e.useEffect((function(){function e(){o(n())}if("undefined"!=typeof window)return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),r},exports.warnAboutMissingStyles=function(){}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");require("tiny-warning");var n=function(){if("undefined"==typeof window)return{width:void 0,height:void 0};var e=window;return{width:e.innerWidth,height:e.innerHeight}};exports.ConditionalWrapper=function(n){var t=n.children;return n.condition?(0,n.wrapper)(t):e.createElement(e.Fragment,null,t)},exports.mergeRefs=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return function(e){for(var t=0,r=n;t<r.length;t++){var u=r[t];"function"==typeof u?u(e):u&&(u.current=e)}}},exports.useDebounce=function(n,t){var r=e.useRef();return e.useEffect((function(){return function(){r.current&&clearTimeout(r.current)}}),[]),function(){for(var e=arguments.length,u=new Array(e),o=0;o<e;o++)u[o]=arguments[o];r.current&&clearTimeout(r.current),r.current=setTimeout((function(){n.apply(void 0,u)}),t)}},exports.useForceUpdate=function(){var n=e.useState(0)[1];return function(){return n((function(e){return e+1}))}},exports.useOnClickOutside=function(n,t){e.useEffect((function(){var e=function(e){n.some((function(n){return function(e,n){return!(!e||!(e.contains(n.target)||n.composed&&n.composedPath&&n.composedPath().find((function(n){return n!==window&&e.contains(n)}))))}(n.current,e)}))||t()};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),function(){document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}}),[n,t])},exports.useOnEscape=function(n,t){e.useEffect((function(){var e=function(e){"Escape"===e.key&&t()},r=n.current;return null==r||r.addEventListener("keydown",e),function(){return null==r?void 0:r.removeEventListener("keydown",e)}}),[n,t])},exports.useOnMount=function(n){var t=e.useRef(!1);e.useEffect((function(){t.current||(t.current=!0,n())}),[n])},exports.useRandomId=function(n){return n+"-"+e.useRef(String(Math.random()).substring(2)).current},exports.useWindowDimensions=function(){var t=e.useState(n()),r=t[0],u=t[1];return e.useEffect((function(){function e(){u(n())}if("undefined"!=typeof window)return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),r},exports.warnAboutMissingStyles=function(){}; | ||
//# sourceMappingURL=utils.cjs.production.min.js.map |
@@ -1,15 +0,25 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import React, { useRef, useEffect, useState } from 'react'; | ||
import warning from 'tiny-warning'; | ||
function debounce(fn, delay) { | ||
var id; | ||
return function () { | ||
function useDebounce(callBack, debounceTime) { | ||
var timeoutRef = useRef(); | ||
useEffect(function () { | ||
return function () { | ||
if (timeoutRef.current) { | ||
clearTimeout(timeoutRef.current); | ||
} | ||
}; | ||
}, []); | ||
var debouncedFunc = function debouncedFunc() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
clearTimeout(id); | ||
id = setTimeout(function () { | ||
return fn.apply(void 0, args); | ||
}, delay); | ||
if (timeoutRef.current) { | ||
clearTimeout(timeoutRef.current); | ||
} | ||
timeoutRef.current = setTimeout(function () { | ||
callBack.apply(void 0, args); | ||
}, debounceTime); | ||
}; | ||
return debouncedFunc; | ||
} | ||
@@ -178,3 +188,3 @@ | ||
export { ConditionalWrapper, debounce, mergeRefs, useForceUpdate, useOnClickOutside, useOnEscape, useOnMount, useRandomId, useWindowDimensions, warnAboutMissingStyles }; | ||
export { ConditionalWrapper, mergeRefs, useDebounce, useForceUpdate, useOnClickOutside, useOnEscape, useOnMount, useRandomId, useWindowDimensions, warnAboutMissingStyles }; | ||
//# sourceMappingURL=utils.esm.js.map |
{ | ||
"name": "@entur/utils", | ||
"version": "0.9.5", | ||
"version": "1.0.0-beta.0", | ||
"license": "EUPL-1.2", | ||
@@ -31,3 +31,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "9b8d4e5d2e6f7a74256371e30ebef43e046c9338" | ||
"gitHead": "4e2a54a5b8402cf439cd91487f569e775bf53691" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
73241
461