Skip to content

Commit

Permalink
Rename cleanupEvents to cleanupListeners
Browse files Browse the repository at this point in the history
  • Loading branch information
emlun committed Dec 6, 2024
1 parent c60bf44 commit 0fc563a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/components/Auth/PrivateRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useSessionStorage } from '../../hooks/useStorage';
import StatusContext from '../../context/StatusContext';
import SessionContext from '../../context/SessionContext';
import { ApiEvent } from '../../api';
import { cleanupEvents } from '../../util';
import { cleanupListeners } from '../../util';


type PrivateRouteContextValue = {
Expand All @@ -31,7 +31,7 @@ export function NotificationPermissionWarning(): React.ReactNode {
const [isMessageOfflineVisible, setIsMessageOfflineVisible, clearIsMessageOfflineVisible] = useSessionStorage('isMessageOfflineVisible', false);

useEffect(
() => cleanupEvents(signal => {
() => cleanupListeners(signal => {
sessionEvents.addEventListener(ApiEvent.ClearSession, clearIsMessageNoGrantedVisible, { signal });
sessionEvents.addEventListener(ApiEvent.ClearSession, clearIsMessageGrantedVisible, { signal });
sessionEvents.addEventListener(ApiEvent.ClearSession, clearIsMessageOfflineVisible, { signal });
Expand Down Expand Up @@ -152,7 +152,7 @@ const PrivateRoute = ({ children }: { children?: React.ReactNode }): React.React
const [latestIsOnlineStatus, setLatestIsOnlineStatus, clearLatestIsOnlineStatus] = useSessionStorage('latestIsOnlineStatus', null);

useEffect(
() => cleanupEvents(signal => {
() => cleanupListeners(signal => {
sessionEvents.addEventListener(ApiEvent.ClearSession, () => {
clearTokenSentInSession();
clearLatestIsOnlineStatus();
Expand Down
4 changes: 2 additions & 2 deletions src/context/ContainerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import StatusContext from "./StatusContext";
import { getSdJwtVcMetadata } from "../lib/utils/getSdJwtVcMetadata";
import { CredentialBatchHelper } from "../lib/services/CredentialBatchHelper";
import { ApiEvent } from "../api";
import { cleanupEvents } from "../util";
import { cleanupListeners } from "../util";

export type ContainerContextValue = {
httpProxy: IHttpProxy,
Expand Down Expand Up @@ -55,7 +55,7 @@ export const ContainerContextProvider = ({ children }) => {
const [shouldUseCache, setShouldUseCache] = useState(true)

useEffect(
() => cleanupEvents(signal => {
() => cleanupListeners(signal => {
const onLogin = () => {
setIsInitialized(false);
setShouldUseCache(false)
Expand Down
4 changes: 2 additions & 2 deletions src/context/SessionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import StatusContext from './StatusContext';
import { BackendApi, useApi } from '../api';
import { KeystoreEvent, useLocalStorageKeystore } from '../services/LocalStorageKeystore';
import type { LocalStorageKeystore } from '../services/LocalStorageKeystore';
import { cleanupEvents } from '../util';
import { cleanupListeners } from '../util';


type SessionContextValue = {
Expand Down Expand Up @@ -40,7 +40,7 @@ export const SessionContextProvider = ({ children }) => {
);

useEffect(
() => cleanupEvents(signal => {
() => cleanupListeners(signal => {
events.addEventListener(KeystoreEvent.Close, logout, { once: true, signal });
events.addEventListener(KeystoreEvent.CloseTabLocal, api.clearSession, { once: true, signal });
}),
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useOnUserInactivity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from 'react';
import { useResettableTimeout } from './useResettableTimeout';
import { cleanupEvents, throttle } from '../util';
import { cleanupListeners, throttle } from '../util';


/**
Expand All @@ -12,7 +12,7 @@ export function useOnUserInactivity(action: () => void, timeoutMillis: number) {
const resetTimeout = useResettableTimeout(action, timeoutMillis);

useEffect(
() => cleanupEvents(signal => {
() => cleanupListeners(signal => {
// I would have liked to use the User Activation API
// (https://developer.mozilla.org/en-US/docs/Web/API/UserActivation/isActive)
// for this, but it doesn't appear to provide an event source and the
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export function getElementPropValue(
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#signal
*/
export function cleanupEvents(effect: (signal: AbortSignal) => (void | (() => void))): () => void {
export function cleanupListeners(effect: (signal: AbortSignal) => (void | (() => void))): () => void {
const abortController = new AbortController();
const signal = abortController.signal;
const cleanup = effect(signal);
Expand Down

0 comments on commit 0fc563a

Please sign in to comment.