mirror of
https://github.com/Xevion/Pac-Man.git
synced 2026-01-31 06:25:09 -06:00
- Implement navigation state tracking with optimistic UI updates - Add loading spinner and error handling for WASM initialization - Insert browser yield points during game initialization to prevent freezing - Redesign leaderboard with tabbed navigation and mock data structure - Add utility CSS classes for consistent page layouts
25 lines
703 B
TypeScript
25 lines
703 B
TypeScript
import { useSyncExternalStore } from "react";
|
|
|
|
type Listener = (pendingUrl: string | null) => void;
|
|
|
|
let pendingUrl: string | null = null;
|
|
const listeners = new Set<Listener>();
|
|
|
|
export function setPendingNavigation(url: string | null) {
|
|
pendingUrl = url;
|
|
listeners.forEach((listener) => listener(pendingUrl));
|
|
}
|
|
|
|
export function getPendingNavigation(): string | null {
|
|
return pendingUrl;
|
|
}
|
|
|
|
export function subscribeToPendingNavigation(listener: Listener): () => void {
|
|
listeners.add(listener);
|
|
return () => listeners.delete(listener);
|
|
}
|
|
|
|
export function usePendingNavigation(): string | null {
|
|
return useSyncExternalStore(subscribeToPendingNavigation, getPendingNavigation, () => null);
|
|
}
|