Proposals
Previews of shipped and possible changes across BlaC packages, written for review before anything more is built.
Each page shows the API, code it improves (before and after), the differences to review, and open questions. Feedback is welcome on any of them, especially the open questions.
Goals
The proposals come from migrating a large production codebase (an admin dashboard and a mobile web app sharing one API layer) off hand-written loading, caching and event code. They aim to:
- Remove app workarounds, not add features: each page counts the hand-written code it replaces.
- Keep containers plain and testable: state stays plain data that tests can seed, and effects are tied to a container’s activation, so they clean up on their own.
- Stay UI-free: dialogs, forms and tables are built in the app. BlaC offers small primitives they build on, such as
ask()and form primitives, not components. - Generalize: every primitive must be useful outside the codebase that motivated it.
Pages are grouped by the package they change, the same as the sidebar. Also touches tags a page that changes or relies on another package too.
@blac/async
| Page | Status | Also touches | Adds | Replaces | Effort |
|---|---|---|---|---|---|
| Mutation concurrency | Proposed | Ordered slot, exclusive, keyed mutations | isSubmitting guards and per-row loading-id sets | ~0.5d | |
| Resource input | Proposed | input: (state) => …, debounce | Manual reload() after filter changes, request-id guards | ~4h | |
| Lifecycle hooks | Proposed | Plugins (DevTools) | configureAsync({ onStart, onSettled }), meta | Copy-pasted breadcrumbs and duration metrics | ~2h |
| Realtime refetch | Proposed | Event sources, refetchOn, refetchInterval | Socket watchers, coalescing flags, polling and focus listeners | 1–1.5d | |
| Retry after token refresh | Proposed | retryFailed(registry?) | An app-wide token-refresh event and per-container last params | ~3h | |
ask() | Proposed | An awaitable request the UI answers | Dialog callbacks and hand-wrapped promises | ~2h | |
| Form primitives | Proposed | @blac/core, Plugins (Persistence) | configureAsync({ normalizeError }) | Form-ready flags, toast-only server validation | ~2h |
The earlier list query proposal (listResource) is superseded by resource input: with an input derived from state, a list container is a query slot plus one resource.
Later
all(a, b, …): combine severalAsyncStateslots into one status (loading if any is loading, error if any failed), for screens with three loading flags and one spinner. ~1h.- Persisted resource cache: the persist plugin on a resource slot plus
staleTimegives stale-while-revalidate across sessions. - DevTools: show async slots, their tags and the invalidation log, once lifecycle hooks exist.
Not proposed
- A normalized entity cache: no container in the surveyed code shares an id map.
- Suspense integration.
- Generic undo.
- A declarative
requires: { flag, capability }:enabledplusdepend()covers it without a new concept. - A dialog or form package: see Goals.
@blac/core
| Page | Status | Also touches | Replaces |
|---|---|---|---|
| Activation-scoped timers | Proposed | @blac/async | Hand-managed timeouts, intervals and component-held debounce |
| Typed step machine | Proposed, recipe first | patch({ step }) writes and ad hoc transition guards | |
| Typed clearWhere | Proposed | instanceof checks and optional chaining in reset predicates | |
| Borrow by key | Closed | Repeating full args at lookup call sites |
Shipped
These started as proposals and are now documented in the reference, each with a “before and after” for migrating from the hand-written version:
clearWhere: Instance Management, replacing app-wide reset events.watch({ signal })andonActivated: watch(), replacing hand-written subscription bridges.isolated:useBloc(), replacing a per-mountuseIdplusstatic key.waitForState,renderWithBlocs,withBlocs: Core Testing and React Testing, replacing polling,useBlocmocks and per-app Storybook decorators.- Web storage persistence: Persistence, replacing hand-written
localStoragehelpers. - Async refinements: Async Resources. A mutation resolves its settled
AsyncState,resource.setwrites locally,enabledgates a resource,optimisticwrites with rollback, a deactivated load restores the exact previous state, andretryOnis removed. Tags follow a two-level convention (['user', 'user:42']).
Release and adoption (all packages)
| Page | Status | What | Effort |
|---|---|---|---|
| Release readiness | Proposed | Changesets for shipped features, API report for async | ~3h |
| Adoption pilot | Proposed | Run the APIs in a real app before building the larger proposals | 1–2d |
Suggested order
- Mutation concurrency and resource input. ~1d.
- Lifecycle hooks and activation-scoped timers: small, and they remove the most copy-paste. ~0.5d.
- Release readiness, then the adoption pilot.
- Realtime refetch, shaped by the pilot’s socket-driven container. 1–1.5d.
- Retry after token refresh and the smaller helpers.
ask(), form primitives, then the step machine recipe.
About the examples
The “before” code is a typical shape adapted from production apps and simplified, with names changed. It is not copied from a real codebase, and the “before” tests are typical shapes as well. Counts such as “about 80 copies” come from searching one production codebase and are estimates. “After” code for Proposed pages is illustrative and not compiled, because those APIs do not exist yet.