diff --git a/.github/workflows/static_analysis.yaml b/.github/workflows/static_analysis.yaml index 82a99190a4..4df819375a 100644 --- a/.github/workflows/static_analysis.yaml +++ b/.github/workflows/static_analysis.yaml @@ -74,3 +74,21 @@ jobs: - name: Run Linter run: "yarn run lint:style" + + analyse_dead_code: + name: "Analyse Dead Code" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-node@v3 + with: + cache: 'yarn' + + - name: Install Deps + run: "scripts/ci/layered.sh" + + - name: Dead Code Analysis + run: | + cd element-web + yarn run analyse:unused-exports diff --git a/src/hooks/useEventEmitter.ts b/src/hooks/useEventEmitter.ts index 3ae011f4ab..46a7d8f184 100644 --- a/src/hooks/useEventEmitter.ts +++ b/src/hooks/useEventEmitter.ts @@ -68,43 +68,6 @@ export function useEventEmitter( ); } -/** - * Hook to wrap an EventTarget addEventListener and removeEventListener in hook - * lifecycle - */ -export function useEventTarget( - emitter: EventTarget | undefined, - eventName: string, - handler: Handler, -): void { - // Create a ref that stores handler - const savedHandler = useRef(handler); - - // Update ref.current value if handler changes. - useEffect(() => { - savedHandler.current = handler; - }, [handler]); - - useEffect( - () => { - // allow disabling this hook by passing a falsy emitter - if (!emitter) return; - - // Create event listener that calls handler function stored in ref - const eventListener = (...args) => savedHandler.current(...args); - - // Add event listener - emitter.addEventListener(eventName, eventListener); - - // Remove event listener on cleanup - return () => { - emitter.removeEventListener(eventName, eventListener); - }; - }, - [eventName, emitter], // Re-run if eventName or emitter changes - ); -} - type Mapper = (...args: any[]) => T; export function useTypedEventEmitterState< @@ -133,18 +96,3 @@ export function useEventEmitterState( useEventEmitter(emitter, eventName, handler); return value; } - -export function useEventTargetState( - target: EventTarget | undefined, - eventName: string, - fn: Mapper, -): T { - const [value, setValue] = useState(fn()); - const handler = useCallback((...args: any[]) => { - setValue(fn(...args)); - }, [fn]); - // re-run when the emitter changes - useEffect(handler, [target]); // eslint-disable-line react-hooks/exhaustive-deps - useEventTarget(target, eventName, handler); - return value; -}