core-ui-state
State management & presenter — StateMachine, Flow, presenter registry, view adapters
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import { StateMachine, Flow } from '@sbx/core-ui/state';
// Typed state machine
const auth = new StateMachine({
initial: 'idle',
states: {
idle: { LOGIN: 'authenticating' },
authenticating: { SUCCESS: 'authenticated', FAILURE: 'idle' },
authenticated: { LOGOUT: 'idle' },
}
});
auth.send('LOGIN'); // → 'authenticating'
// Async flow
const fetchFlow = new Flow<User[]>();
fetchFlow.loading();
const users = await api.getUsers();
fetchFlow.success(users); // or fetchFlow.error(err)About
Application state and presentation infrastructure. StateMachine provides finite-state-machine with typed transitions. Flow manages async operation lifecycle (idle → loading → success/error). The presenter layer includes a component registry for dynamic rendering, fixture loading for storybook-style previews, and view adapters for transforming API data into component props.
Public API
| Name | Kind | Signature |
|---|---|---|
| StateMachine | type | class StateMachine<S, E> — states, transitions, current, send(event) |
| Flow | type | class Flow<T> — idle, loading, success(data), error(err) |
| componentRegistry | func | componentRegistry: Map<string, ComponentRepresentation> |
| PresenterFixtures | type | class PresenterFixtures — load(name), list(), register(fixture) |
| FixtureLoader | type | class FixtureLoader — loadAll(glob), loadOne(path) |
| ActivityRegistry | type | class ActivityRegistry — register(type, handler), dispatch(activity) |
| MotionTokens | type | MotionTokens — duration, easing, stagger constants |
Dependencies
Imported By (2)
Composite UI blocks — NavRail, CommandPalette, ChatWidget, FileTree, Editors
Page sections & layouts — AdminTemplate, ContentSidebar, EntityDetail, Canvas
Related Packages
Branding & style system — brand config, CSS custom properties, contrast validation
Composite UI blocks — NavRail, CommandPalette, ChatWidget, FileTree, Editors