Skip to content

Commit

Permalink
Update use-propagate
Browse files Browse the repository at this point in the history
  • Loading branch information
OEvgeny committed Apr 30, 2024
1 parent ea45886 commit 50881d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 56 deletions.
20 changes: 10 additions & 10 deletions packages/component/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
46 changes: 1 addition & 45 deletions packages/component/src/hooks/sendBoxFocus.ts
Original file line number Diff line number Diff line change
@@ -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<T>(array: T[], ...items: T[]): void {
for (const item of items) {
let index;

while (~(index = array.indexOf(item))) {
array.splice(index, 1);
}
}
}

type Listener<T> = (value: T) => void;

export default function createPropagation<T>() {
type Fn = Listener<T>;

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 }>;

Expand Down

0 comments on commit 50881d6

Please sign in to comment.