one
Version:
One is a React framework for web, iOS, and Android apps.
1 lines • 2.56 kB
Source Map (JSON)
{"version":3,"file":"useMatches.js","names":[],"sources":["esm/useMatches.js"],"sourcesContent":["import { useSyncExternalStore } from \"react\";\nimport { useServerContext } from \"./vite/one-server-only\";\nlet clientMatches = [];\nconst clientMatchesListeners = /* @__PURE__ */ new Set();\nfunction subscribeToClientMatches(callback) {\n clientMatchesListeners.add(callback);\n return () => clientMatchesListeners.delete(callback);\n}\nfunction getClientMatchesSnapshot() {\n return clientMatches;\n}\nfunction setClientMatches(matches) {\n clientMatches = matches;\n queueMicrotask(() => {\n for (const listener of clientMatchesListeners) {\n listener();\n }\n });\n}\nfunction updateMatchLoaderData(routeId, loaderData) {\n clientMatches = clientMatches.map(\n (m) => m.routeId === routeId ? { ...m, loaderData } : m\n );\n for (const listener of clientMatchesListeners) {\n listener();\n }\n}\nfunction useMatches() {\n const serverContext = useServerContext();\n if (process.env.VITE_ENVIRONMENT === \"ssr\") {\n return serverContext?.matches ?? [];\n }\n const clientStoreMatches = useSyncExternalStore(\n subscribeToClientMatches,\n getClientMatchesSnapshot,\n // server snapshot for hydration - must match what SSR rendered\n () => serverContext?.matches ?? []\n );\n return clientStoreMatches;\n}\nfunction useMatch(routeId) {\n const matches = useMatches();\n return matches.find((m) => m.routeId === routeId);\n}\nfunction usePageMatch() {\n const matches = useMatches();\n return matches[matches.length - 1];\n}\nexport {\n getClientMatchesSnapshot,\n setClientMatches,\n subscribeToClientMatches,\n updateMatchLoaderData,\n useMatch,\n useMatches,\n usePageMatch\n};\n//# sourceMappingURL=useMatches.js.map\n"],"mappings":";;;;AAEA,IAAI,gBAAgB,CAAC;AACrB,MAAM,yCAAyC,IAAI,IAAI;AACvD,SAAS,yBAAyB,UAAU;CAC1C,uBAAuB,IAAI,QAAQ;CACnC,aAAa,uBAAuB,OAAO,QAAQ;AACrD;AACA,SAAS,2BAA2B;CAClC,OAAO;AACT;AACA,SAAS,iBAAiB,SAAS;CACjC,gBAAgB;CAChB,qBAAqB;EACnB,KAAK,MAAM,YAAY,wBAAwB;GAC7C,SAAS;EACX;CACF,CAAC;AACH;AACA,SAAS,sBAAsB,SAAS,YAAY;CAClD,gBAAgB,cAAc,KAC3B,MAAM,EAAE,YAAY,UAAU;EAAE,GAAG;EAAG;CAAW,IAAI,CACxD;CACA,KAAK,MAAM,YAAY,wBAAwB;EAC7C,SAAS;CACX;AACF;AACA,SAAS,aAAa;CACpB,MAAM,gBAAgB,iBAAiB;CACvC,IAAI,QAAQ,IAAI,qBAAqB,OAAO;EAC1C,OAAO,eAAe,WAAW,CAAC;CACpC;CACA,MAAM,qBAAqB,qBACzB,0BACA,gCAEM,eAAe,WAAW,CAAC,CACnC;CACA,OAAO;AACT;AACA,SAAS,SAAS,SAAS;CACzB,MAAM,UAAU,WAAW;CAC3B,OAAO,QAAQ,MAAM,MAAM,EAAE,YAAY,OAAO;AAClD;AACA,SAAS,eAAe;CACtB,MAAM,UAAU,WAAW;CAC3B,OAAO,QAAQ,QAAQ,SAAS;AAClC"}