From 50881d683f3cbc564b54643b2b0a0e3736a8c8d5 Mon Sep 17 00:00:00 2001 From: Eugene Olonov Date: Tue, 30 Apr 2024 08:52:07 -0700 Subject: [PATCH] Update use-propagate --- packages/component/package-lock.json | 20 ++++----- packages/component/package.json | 2 +- packages/component/src/hooks/sendBoxFocus.ts | 46 +------------------- 3 files changed, 12 insertions(+), 56 deletions(-) diff --git a/packages/component/package-lock.json b/packages/component/package-lock.json index d4749372b0..7e48a51e7c 100644 --- a/packages/component/package-lock.json +++ b/packages/component/package-lock.json @@ -29,7 +29,7 @@ "react-scroll-to-bottom": "4.2.0", "redux": "5.0.0", "simple-update-in": "2.2.0", - "use-propagate": "^0.0.1-main.b18a4e0", + "use-propagate": "^0.1.0", "use-ref-from": "^0.1.0", "valibot": "^0.30.0" }, @@ -4796,16 +4796,16 @@ } }, "node_modules/use-propagate": { - "version": "0.0.1-main.b18a4e0", - "resolved": "https://registry.npmjs.org/use-propagate/-/use-propagate-0.0.1-main.b18a4e0.tgz", - "integrity": "sha512-hr8wDvMMKxZSAsTImzfAdx+IHKeqO+n8jbY3qdzip0ssLRQ5HtEmf5VWgXQ9HofZXoNIUss7zt8lkTYHe7hiSQ==", + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/use-propagate/-/use-propagate-0.1.0.tgz", + "integrity": "sha512-VkVuUDwLdQzsUKl+ZmK54WHDGmsiXchi/p7ldYJTQF1o7IMFcTy3XnGmiOrG/aMpyWM7QVNwgHA7ZcKNNakZwA==", "dependencies": { "@babel/runtime-corejs3": "^7.24.1", - "use-propagate": "^0.0.1-main.b18a4e0", + "use-propagate": "^0.1.0", "use-ref-from": "^0.0.3" }, "peerDependencies": { - "react": ">=16.9.0" + "react": ">=16.8.0" } }, "node_modules/use-propagate/node_modules/@babel/runtime-corejs3": { @@ -8401,12 +8401,12 @@ } }, "use-propagate": { - "version": "0.0.1-main.b18a4e0", - "resolved": "https://registry.npmjs.org/use-propagate/-/use-propagate-0.0.1-main.b18a4e0.tgz", - "integrity": "sha512-hr8wDvMMKxZSAsTImzfAdx+IHKeqO+n8jbY3qdzip0ssLRQ5HtEmf5VWgXQ9HofZXoNIUss7zt8lkTYHe7hiSQ==", + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/use-propagate/-/use-propagate-0.1.0.tgz", + "integrity": "sha512-VkVuUDwLdQzsUKl+ZmK54WHDGmsiXchi/p7ldYJTQF1o7IMFcTy3XnGmiOrG/aMpyWM7QVNwgHA7ZcKNNakZwA==", "requires": { "@babel/runtime-corejs3": "^7.24.1", - "use-propagate": "^0.0.1-main.b18a4e0", + "use-propagate": "^0.1.0", "use-ref-from": "^0.0.3" }, "dependencies": { diff --git a/packages/component/package.json b/packages/component/package.json index 23c7ce1049..8d9705072a 100644 --- a/packages/component/package.json +++ b/packages/component/package.json @@ -116,7 +116,7 @@ "react-scroll-to-bottom": "4.2.0", "redux": "5.0.0", "simple-update-in": "2.2.0", - "use-propagate": "^0.0.1-main.b18a4e0", + "use-propagate": "^0.1.0", "use-ref-from": "^0.1.0", "valibot": "^0.30.0" }, diff --git a/packages/component/src/hooks/sendBoxFocus.ts b/packages/component/src/hooks/sendBoxFocus.ts index 2b5b29e21c..b5c7cbe44d 100644 --- a/packages/component/src/hooks/sendBoxFocus.ts +++ b/packages/component/src/hooks/sendBoxFocus.ts @@ -1,49 +1,5 @@ import { WaitUntilable } from './internal/createWaitUntilable'; - -// TODO [P0]: remove and use `use-propagate` when it -// is able to work with React v16+ -// import { createPropagation } from 'use-propagate'; -import { useEffect } from 'react'; -import { useRefFrom } from 'use-ref-from'; - -function removeInline(array: T[], ...items: T[]): void { - for (const item of items) { - let index; - - while (~(index = array.indexOf(item))) { - array.splice(index, 1); - } - } -} - -type Listener = (value: T) => void; - -export default function createPropagation() { - type Fn = Listener; - - const listeners: Fn[] = []; - - // eslint-disable-next-line no-void - const addListener = (listener: Fn): void => void listeners.push(listener); - const removeListener = (listener: Fn): void => removeInline(listeners, listener); - const usePropagate = () => (value: T) => listeners.forEach(listener => listener(value)); - - return { - useListen: (listener: Fn) => { - const listenerRef = useRefFrom(listener); - - useEffect(() => { - const wrappingListener = (value: T) => listenerRef.current(value); - - addListener(wrappingListener); - - return () => removeListener(wrappingListener); - }, [listenerRef]); - }, - usePropagate - }; -} -// end of the TODO +import { createPropagation } from 'use-propagate'; export type SendBoxFocusOptions = WaitUntilable<{ noKeyboard: boolean }>;