Skip to content
Logo
ghostry

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.

npm install @ghostry/finity-reactjs
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…</>;
}