alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
82 lines (79 loc) • 2.15 kB
JavaScript
import {
useAtomValue,
useSetAtom,
useStore
} from "../../chunks/chunk-WF77DMLN.js";
import "../../chunks/chunk-ZHH24SIG.js";
import {
atom
} from "../../chunks/chunk-OBOPLPUQ.js";
import {
QueryClient
} from "../../chunks/chunk-DJKGEOOC.js";
import "../../chunks/chunk-U5RRZUYZ.js";
// node_modules/jotai/esm/react/utils.mjs
import { useCallback, useMemo } from "react";
var hydratedMap = /* @__PURE__ */ new WeakMap();
function useHydrateAtoms(values, options) {
const store = useStore(options);
const hydratedSet = getHydratedSet(store);
for (const [atom2, value] of values) {
if (!hydratedSet.has(atom2) || (options == null ? void 0 : options.dangerouslyForceHydrate)) {
hydratedSet.add(atom2);
store.set(atom2, value);
}
}
}
var getHydratedSet = (store) => {
let hydratedSet = hydratedMap.get(store);
if (!hydratedSet) {
hydratedSet = /* @__PURE__ */ new WeakSet();
hydratedMap.set(store, hydratedSet);
}
return hydratedSet;
};
// src/dashboard/atoms/DashboardAtoms.ts
import { useEffect } from "react";
var sessionAtom = atom(void 0);
var dashboardOptionsAtom = atom(void 0);
function useSetDashboardOptions(options) {
useHydrateAtoms([[dashboardOptionsAtom, options]]);
const { client, config, dev } = options;
const auth = config.dashboard?.auth;
if (dev || !auth)
useHydrateAtoms([
[
sessionAtom,
{
user: { sub: "anonymous" },
cnx: client
}
]
]);
const setDashboardOptions = useSetAtom(dashboardOptionsAtom);
useEffect(
() => setDashboardOptions(options),
[options.client, options.config]
);
}
var queryClientAtom = atom(
new QueryClient({ defaultOptions: { queries: { retry: false } } })
);
var clientAtom = atom((get) => {
return get(dashboardOptionsAtom).client;
});
var configAtom = atom((get) => {
return get(dashboardOptionsAtom).config;
});
var useSession = () => useAtomValue(sessionAtom);
var useConfig = () => useAtomValue(configAtom);
export {
clientAtom,
configAtom,
dashboardOptionsAtom,
queryClientAtom,
sessionAtom,
useConfig,
useSession,
useSetDashboardOptions
};