Function bodies 7 total
Toaster function · typescript · L4-L24 (21 LOC)src/components/ui/toaster.tsx
export function Toaster() {
const { toasts } = useToast();
return (
<ToastProvider>
{toasts.map(function ({ id, title, description, action, ...props }) {
return (
<Toast key={id} {...props}>
<div className="grid gap-1">
{title && <ToastTitle>{title}</ToastTitle>}
{description && <ToastDescription>{description}</ToastDescription>}
</div>
{action}
<ToastClose />
</Toast>
);
})}
<ToastViewport />
</ToastProvider>
);
}loadGameState function · typescript · L19-L29 (11 LOC)src/hooks/useGameState.ts
function loadGameState(): GameState {
try {
const saved = localStorage.getItem(STORAGE_KEY);
if (saved) {
return GameStateSchema.parse(JSON.parse(saved));
}
} catch (error) {
console.error("Failed to load game state:", error);
}
return DEFAULT_GAME_STATE;
}genId function · typescript · L24-L27 (4 LOC)src/hooks/use-toast.ts
function genId() {
count = (count + 1) % Number.MAX_SAFE_INTEGER;
return count.toString();
}dispatch function · typescript · L128-L133 (6 LOC)src/hooks/use-toast.ts
function dispatch(action: Action) {
memoryState = reducer(memoryState, action);
listeners.forEach((listener) => {
listener(memoryState);
});
}toast function · typescript · L137-L164 (28 LOC)src/hooks/use-toast.ts
function toast({ ...props }: Toast) {
const id = genId();
const update = (props: ToasterToast) =>
dispatch({
type: "UPDATE_TOAST",
toast: { ...props, id },
});
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
dispatch({
type: "ADD_TOAST",
toast: {
...props,
id,
open: true,
onOpenChange: (open) => {
if (!open) dismiss();
},
},
});
return {
id: id,
dismiss,
update,
};
}useToast function · typescript · L166-L184 (19 LOC)src/hooks/use-toast.ts
function useToast() {
const [state, setState] = React.useState<State>(memoryState);
React.useEffect(() => {
listeners.push(setState);
return () => {
const index = listeners.indexOf(setState);
if (index > -1) {
listeners.splice(index, 1);
}
};
}, [state]);
return {
...state,
toast,
dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
};
}cn function · typescript · L4-L6 (3 LOC)src/lib/utils.ts
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}