alinea
Version:
Headless git-based CMS
32 lines (30 loc) • 790 B
JavaScript
import {
loadable
} from "../../chunks/chunk-WDCPVJJC.js";
import {
atom
} from "../../chunks/chunk-WJ67RR7S.js";
import "../../chunks/chunk-NZLE2WMY.js";
// src/dashboard/util/Loader.ts
function loader(asynAtom) {
const currentAtom = atom(void 0);
return atom(
(get, { setSelf }) => {
const next = get(loadable(asynAtom));
if (next.state === "hasData") setSelf(next.data);
return {
data: next.state === "hasData" ? next.data : get(currentAtom),
error: next.state === "hasError" ? next.error : void 0,
isError: next.state === "hasError",
isLoading: next.state === "loading",
isSuccess: next.state === "hasData"
};
},
(get, set, value) => {
set(currentAtom, value);
}
);
}
export {
loader
};