Files
jp 0917366cdf Separate JSON API backend (vm_api.py) + React+TanStack frontend scaffold
- vm_api.py: pure FastAPI JSON API on :8098 with CORS
- vm-api.service: systemd unit for API (replaces inline HTML vm_web.py for frontend)
- vm_web.py: kept intact as fallback; Apache now proxies /api/ -> :8098
- frontend/: Vite + React + TanStack Query scaffold
- Apache vhost updated: DocumentRoot -> frontend/dist, /api/ proxy, SPA fallback
- All original HTML pages still functional via :8099 during transition
2026-08-13 17:42:33 +01:00

49 lines
2.0 KiB
JavaScript

"use client";
import { dummyMatchContext, matchContext } from "./matchContext.js";
import { useRouter } from "./useRouter.js";
import { invariant, replaceEqualDeep } from "@tanstack/router-core";
import * as React$1 from "react";
import { isServer } from "@tanstack/router-core/isServer";
import { useStore } from "@tanstack/react-store";
//#region src/useMatch.tsx
var dummyMatch = {};
function useStructuralSharing(opts, router) {
const previousResult = React$1.useRef();
return (slice) => {
const selected = opts?.select ? opts.select(slice) : slice;
if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) return previousResult.current = replaceEqualDeep(previousResult.current, selected);
return selected;
};
}
/**
* Read and select the nearest or targeted route match.
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchHook
*/
function useMatch(opts) {
const router = useRouter();
const nearestRouteId = React$1.useContext(opts.from ? dummyMatchContext : matchContext);
const routeId = opts.from ?? nearestRouteId;
const matchStore = router.stores.getMatchStore(routeId);
if (isServer ?? router.isServer) {
const match = matchStore.get();
if (!match) {
if (opts.shouldThrow ?? true) {
if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`);
invariant();
}
return;
}
return opts.select ? opts.select(match) : match;
}
const selector = useStructuralSharing(opts, router);
const matchSelection = useStore(matchStore, (match) => match ? selector(match) : dummyMatch);
if (matchSelection !== dummyMatch) return matchSelection;
if (opts.shouldThrow ?? true) {
if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`);
invariant();
}
}
//#endregion
export { useMatch, useStructuralSharing };
//# sourceMappingURL=useMatch.js.map