Skip to content

Commit 85730f5

Browse files
committed
refactor(react): memoize getIsPassiveListenerSupported via IIFE
Convert the closure factory into an IIFE so the memoization state is captured once at module load instead of per call. Also add a TODO to abstract the global `window` reference behind an environment provider.
1 parent 1dac68e commit 85730f5

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

  • packages/react/src/resize-handle

packages/react/src/resize-handle/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const getIsPassiveListenerSupported = () => {
1+
export const getIsPassiveListenerSupported = (() => {
22
let isPassiveListenerSupported = null;
33

44
return () => {
@@ -16,6 +16,7 @@ export const getIsPassiveListenerSupported = () => {
1616

1717
const noop = () => {};
1818

19+
// TODO: Use environment provider to obtain the global object and avoid referencing `window` directly
1920
window.addEventListener('test', noop, options);
2021
window.removeEventListener('test', noop);
2122
} catch (_error) {
@@ -24,4 +25,4 @@ export const getIsPassiveListenerSupported = () => {
2425

2526
return isPassiveListenerSupported;
2627
};
27-
};
28+
})();

0 commit comments

Comments
 (0)