New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@leafygreen-ui/hooks

Package Overview
Dependencies
Maintainers
3
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafygreen-ui/hooks - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

CHANGELOG.md

2

dist/index.js

@@ -1,2 +0,2 @@

!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var n="object"==typeof exports?t(require("react")):t(e.react);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(t,n){t.exports=e},function(e,t){e.exports=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}},function(e,t,n){var r=n(11),o="object"==typeof self&&self&&self.Object===Object&&self,u=r||o||Function("return this")();e.exports=u},function(e,t,n){var r=n(2).Symbol;e.exports=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"useEventListener",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(t,"useElementNode",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(t,"useMutationObserver",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(t,"useViewportSize",{enumerable:!0,get:function(){return i.default}});var r=f(n(5)),o=f(n(6)),u=f(n(7)),i=f(n(8));function f(e){return e&&e.__esModule?e:{default:e}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=n.options,u=n.enabled,i=void 0===u||u,f=n.dependencies,c=void 0===f?[i,e]:f,a=n.element,l=void 0===a?document:a,s=(0,r.useRef)(function(){});(0,r.useEffect)(function(){s.current=t},[t]),(0,r.useEffect)(function(){if(i){return l.addEventListener(e,function(e){return s.current(e)},o),function(){l.removeEventListener(e,t,o)}}},c)};var r=n(0)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){var e=(u=(0,r.useState)(null),i=2,function(e){if(Array.isArray(e))return e}(u)||function(e,t){var n=[],r=!0,o=!1,u=void 0;try{for(var i,f=e[Symbol.iterator]();!(r=(i=f.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){o=!0,u=e}finally{try{r||null==f.return||f.return()}finally{if(o)throw u}}return n}(u,i)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()),t=e[0],n=e[1],o=(0,r.useCallback)(function(e){e&&n(e)},[]);var u,i;return[t,o]};var r=n(0)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,n){var o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=(c=(0,r.useState)(),a=2,function(e){if(Array.isArray(e))return e}(c)||function(e,t){var n=[],r=!0,o=!1,u=void 0;try{for(var i,f=e[Symbol.iterator]();!(r=(i=f.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){o=!0,u=e}finally{try{r||null==f.return||f.return()}finally{if(o)throw u}}return n}(c,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()),i=u[0],f=u[1];var c,a;return(0,r.useEffect)(function(){if(o){var r=new MutationObserver(function(){f(n.apply(void 0,arguments))});return e&&r.observe(e,t),function(){return r.disconnect()}}},[e,t,n,o]),i};var r=n(0)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){var e=(r=(0,o.useState)(i),f=2,function(e){if(Array.isArray(e))return e}(r)||function(e,t){var n=[],r=!0,o=!1,u=void 0;try{for(var i,f=e[Symbol.iterator]();!(r=(i=f.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){o=!0,u=e}finally{try{r||null==f.return||f.return()}finally{if(o)throw u}}return n}(r,f)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()),t=e[0],n=e[1];var r,f;return(0,o.useEffect)(function(){var e=(0,u.default)(function(){return n(i())},100);return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}},[]),t};var r,o=n(0),u=(r=n(9))&&r.__esModule?r:{default:r};function i(){return{width:window.innerWidth,height:window.innerHeight}}},function(e,t,n){var r=n(1),o=n(10),u=n(13),i="Expected a function",f=Math.max,c=Math.min;e.exports=function(e,t,n){var a,l,s,d,v,p,y=0,b=!1,m=!1,h=!0;if("function"!=typeof e)throw new TypeError(i);function j(t){var n=a,r=l;return a=l=void 0,y=t,d=e.apply(r,n)}function x(e){var n=e-p;return void 0===p||n>=t||n<0||m&&e-y>=s}function w(){var e=o();if(x(e))return g(e);v=setTimeout(w,function(e){var n=t-(e-p);return m?c(n,s-(e-y)):n}(e))}function g(e){return v=void 0,h&&a?j(e):(a=l=void 0,d)}function O(){var e=o(),n=x(e);if(a=arguments,l=this,p=e,n){if(void 0===v)return function(e){return y=e,v=setTimeout(w,t),b?j(e):d}(p);if(m)return v=setTimeout(w,t),j(p)}return void 0===v&&(v=setTimeout(w,t)),d}return t=u(t)||0,r(n)&&(b=!!n.leading,s=(m="maxWait"in n)?f(u(n.maxWait)||0,t):s,h="trailing"in n?!!n.trailing:h),O.cancel=function(){void 0!==v&&clearTimeout(v),y=0,a=p=l=v=void 0},O.flush=function(){return void 0===v?d:g(o())},O}},function(e,t,n){var r=n(2);e.exports=function(){return r.Date.now()}},function(e,t,n){(function(t){var n="object"==typeof t&&t&&t.Object===Object&&t;e.exports=n}).call(this,n(12))},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){var r=n(1),o=n(14),u=NaN,i=/^\s+|\s+$/g,f=/^[-+]0x[0-9a-f]+$/i,c=/^0b[01]+$/i,a=/^0o[0-7]+$/i,l=parseInt;e.exports=function(e){if("number"==typeof e)return e;if(o(e))return u;if(r(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=r(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(i,"");var n=c.test(e);return n||a.test(e)?l(e.slice(2),n?2:8):f.test(e)?u:+e}},function(e,t,n){var r=n(15),o=n(18),u="[object Symbol]";e.exports=function(e){return"symbol"==typeof e||o(e)&&r(e)==u}},function(e,t,n){var r=n(3),o=n(16),u=n(17),i="[object Null]",f="[object Undefined]",c=r?r.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?f:i:c&&c in Object(e)?o(e):u(e)}},function(e,t,n){var r=n(3),o=Object.prototype,u=o.hasOwnProperty,i=o.toString,f=r?r.toStringTag:void 0;e.exports=function(e){var t=u.call(e,f),n=e[f];try{e[f]=void 0;var r=!0}catch(e){}var o=i.call(e);return r&&(t?e[f]=n:delete e[f]),o}},function(e,t){var n=Object.prototype.toString;e.exports=function(e){return n.call(e)}},function(e,t){e.exports=function(e){return null!=e&&"object"==typeof e}}])});
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var n="object"==typeof exports?t(require("react")):t(e.react);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(t,n){t.exports=e},function(e,t){e.exports=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}},function(e,t,n){var r=n(11),o="object"==typeof self&&self&&self.Object===Object&&self,u=r||o||Function("return this")();e.exports=u},function(e,t,n){var r=n(2).Symbol;e.exports=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"useEventListener",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(t,"useElementNode",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(t,"useMutationObserver",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(t,"useViewportSize",{enumerable:!0,get:function(){return i.default}});var r=f(n(5)),o=f(n(6)),u=f(n(7)),i=f(n(8));function f(e){return e&&e.__esModule?e:{default:e}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=n.options,u=n.enabled,i=void 0===u||u,f=n.dependencies,c=void 0===f?[i,e]:f,a=n.element,l=void 0===a?document:a,s=(0,r.useRef)(function(){});(0,r.useEffect)(function(){s.current=t},[t]),(0,r.useEffect)(function(){if(i){var t=function(e){return s.current(e)};return l.addEventListener(e,t,o),function(){l.removeEventListener(e,t,o)}}},c)};var r=n(0)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){var e=(u=(0,r.useState)(null),i=2,function(e){if(Array.isArray(e))return e}(u)||function(e,t){var n=[],r=!0,o=!1,u=void 0;try{for(var i,f=e[Symbol.iterator]();!(r=(i=f.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){o=!0,u=e}finally{try{r||null==f.return||f.return()}finally{if(o)throw u}}return n}(u,i)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()),t=e[0],n=e[1],o=(0,r.useCallback)(function(e){e&&n(e)},[]);var u,i;return[t,o]};var r=n(0)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,n){var o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=(c=(0,r.useState)(),a=2,function(e){if(Array.isArray(e))return e}(c)||function(e,t){var n=[],r=!0,o=!1,u=void 0;try{for(var i,f=e[Symbol.iterator]();!(r=(i=f.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){o=!0,u=e}finally{try{r||null==f.return||f.return()}finally{if(o)throw u}}return n}(c,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()),i=u[0],f=u[1];var c,a;return(0,r.useEffect)(function(){if(o){var r=new MutationObserver(function(){f(n.apply(void 0,arguments))});return e&&r.observe(e,t),function(){return r.disconnect()}}},[e,t,n,o]),i};var r=n(0)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){var e=(r=(0,o.useState)(i),f=2,function(e){if(Array.isArray(e))return e}(r)||function(e,t){var n=[],r=!0,o=!1,u=void 0;try{for(var i,f=e[Symbol.iterator]();!(r=(i=f.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){o=!0,u=e}finally{try{r||null==f.return||f.return()}finally{if(o)throw u}}return n}(r,f)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()),t=e[0],n=e[1];var r,f;return(0,o.useEffect)(function(){var e=(0,u.default)(function(){return n(i())},100);return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}},[]),t};var r,o=n(0),u=(r=n(9))&&r.__esModule?r:{default:r};function i(){return{width:window.innerWidth,height:window.innerHeight}}},function(e,t,n){var r=n(1),o=n(10),u=n(13),i="Expected a function",f=Math.max,c=Math.min;e.exports=function(e,t,n){var a,l,s,d,v,p,y=0,b=!1,m=!1,h=!0;if("function"!=typeof e)throw new TypeError(i);function j(t){var n=a,r=l;return a=l=void 0,y=t,d=e.apply(r,n)}function x(e){var n=e-p;return void 0===p||n>=t||n<0||m&&e-y>=s}function w(){var e=o();if(x(e))return g(e);v=setTimeout(w,function(e){var n=t-(e-p);return m?c(n,s-(e-y)):n}(e))}function g(e){return v=void 0,h&&a?j(e):(a=l=void 0,d)}function O(){var e=o(),n=x(e);if(a=arguments,l=this,p=e,n){if(void 0===v)return function(e){return y=e,v=setTimeout(w,t),b?j(e):d}(p);if(m)return clearTimeout(v),v=setTimeout(w,t),j(p)}return void 0===v&&(v=setTimeout(w,t)),d}return t=u(t)||0,r(n)&&(b=!!n.leading,s=(m="maxWait"in n)?f(u(n.maxWait)||0,t):s,h="trailing"in n?!!n.trailing:h),O.cancel=function(){void 0!==v&&clearTimeout(v),y=0,a=p=l=v=void 0},O.flush=function(){return void 0===v?d:g(o())},O}},function(e,t,n){var r=n(2);e.exports=function(){return r.Date.now()}},function(e,t,n){(function(t){var n="object"==typeof t&&t&&t.Object===Object&&t;e.exports=n}).call(this,n(12))},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){var r=n(1),o=n(14),u=NaN,i=/^\s+|\s+$/g,f=/^[-+]0x[0-9a-f]+$/i,c=/^0b[01]+$/i,a=/^0o[0-7]+$/i,l=parseInt;e.exports=function(e){if("number"==typeof e)return e;if(o(e))return u;if(r(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=r(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(i,"");var n=c.test(e);return n||a.test(e)?l(e.slice(2),n?2:8):f.test(e)?u:+e}},function(e,t,n){var r=n(15),o=n(18),u="[object Symbol]";e.exports=function(e){return"symbol"==typeof e||o(e)&&r(e)==u}},function(e,t,n){var r=n(3),o=n(16),u=n(17),i="[object Null]",f="[object Undefined]",c=r?r.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?f:i:c&&c in Object(e)?o(e):u(e)}},function(e,t,n){var r=n(3),o=Object.prototype,u=o.hasOwnProperty,i=o.toString,f=r?r.toStringTag:void 0;e.exports=function(e){var t=u.call(e,f),n=e[f];try{e[f]=void 0;var r=!0}catch(e){}var o=i.call(e);return r&&(t?e[f]=n:delete e[f]),o}},function(e,t){var n=Object.prototype.toString;e.exports=function(e){return n.call(e)}},function(e,t){e.exports=function(e){return null!=e&&"object"==typeof e}}])});
//# sourceMappingURL=index.js.map
{
"name": "@leafygreen-ui/hooks",
"version": "1.0.6",
"version": "1.0.7",
"description": "LeafyGreen UI Kit Custom Hooks",

@@ -8,4 +8,3 @@ "main": "./dist/index.js",

"scripts": {
"build": "../../node_modules/.bin/webpack --config ../../webpack.config.js",
"ts:emit": "tsc --project ./tsconfig.json"
"build": "../../node_modules/.bin/webpack --config ../../webpack.config.js"
},

@@ -17,2 +16,2 @@ "license": "Apache-2.0",

"gitHead": "dd71a2d404218ccec2e657df9c0263dc1c15b9e0"
}
}
import React, { useEffect } from 'react';
import { act, renderHook } from 'react-hooks-testing-library';
import { act, renderHook } from '@testing-library/react-hooks';
import { render, cleanup } from '@testing-library/react';

@@ -10,3 +10,3 @@ import { useEventListener, useElementNode, useViewportSize } from './index';

describe('useEventListener', () => {
test('event callback should fire when enabled is true', () => {
test('event callback should only fire when enabled is true', () => {
const eventCallback = jest.fn();

@@ -27,5 +27,3 @@

renderHook(() =>
useEventListener({
type: 'click',
eventCallback,
useEventListener('click', eventCallback, {
enabled: false,

@@ -41,2 +39,51 @@ }),

});
test('event callback should not fire when enabled is toggled false after being set to true', () => {
const eventCallback = jest.fn();
let initialValue = { enabled: true };
const { rerender } = renderHook(() =>
useEventListener('click', eventCallback, initialValue),
);
act(() => {
document.body.dispatchEvent(new MouseEvent('click', { bubbles: true }));
});
expect(eventCallback).toHaveBeenCalledTimes(1);
initialValue = { enabled: false };
eventCallback.mockReset();
rerender();
act(() => {
document.body.dispatchEvent(new MouseEvent('click', { bubbles: true }));
});
expect(eventCallback).toHaveBeenCalledTimes(0);
});
test('changing a dependency does not create an additional event listener', () => {
const eventCallback = jest.fn();
let initialValue = { enabled: true, dependencies: ['a'] };
const { rerender } = renderHook(() =>
useEventListener('click', eventCallback, initialValue),
);
act(() => {
document.body.dispatchEvent(new MouseEvent('click', { bubbles: true }));
});
expect(eventCallback).toHaveBeenCalledTimes(1);
initialValue = { enabled: true, dependencies: ['b'] };
rerender();
act(() => {
document.body.dispatchEvent(new MouseEvent('click', { bubbles: true }));
});
expect(eventCallback).toHaveBeenCalledTimes(2);
});
});

@@ -43,0 +90,0 @@

@@ -52,9 +52,5 @@ import { useEffect, useRef } from 'react';

return () => {
element.removeEventListener(
type,
eventCallback as EventListener,
options,
);
element.removeEventListener(type, callback as EventListener, options);
};
}, dependencies);
}
{
"extends": "../../package.tsconfig.json",
"compilerOptions": {
"declarationDir": "dist"
"declarationDir": "dist",
"rootDir": "src"
},
"include": ["./**/*"]
"include": ["src/**/*"]
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc