
finity
Finite state with exhaustive cases and enforced transitions.
Declare a component's states and which state may follow which. TypeScript then rejects a missing case and a transition you didn't declare, and finity reports a stale one at runtime.
const =
.<{
: {};
: { : string; : string };
: { : string };
: { : string };
}>("SignIn")
.({
: ["SigningIn"],
: ["SignedIn", "Rejected"],
: ["SigningIn"],
: [],
});
type = <typeof >;
function () {
const = .(, () => ({
: "SignedOut",
}));
return
.(.)
.(["SignedOut", "Rejected"], ({ }) => (
<
={() =>
({ : "SigningIn", ... })
}
/>
))
.(["SigningIn"], () => < ={} />)
.(["SignedIn"], ({ }) => <>Welcome, {}.</>)
.();
}
function ({ }: { : ["SigningIn"] }) {
(() => {
const { , , } = ;
.(, )
.(() => ({ : "SignedIn", }))
.(() => ({ : "Rejected", }));
}, []);
return <>Signing in…</>;
}A component is in exactly one named state, and each state carries only the data it has. No isLoading beside an error that might be stale.
Each state lists the states that may follow it. A transition you didn't declare doesn't compile, and a terminal state has no transitions at all.
useRender takes one case per state, and its chain only ends when every state is handled. A new state is a type error everywhere it's missing.
A transition from a state the component has already left is ignored and reported, so a slow request can't overwrite a newer state.
One API on both, built on each framework's own state. Another framework takes a small adapter over @ghostry/finity-core.
finity needs your framework and nothing else.