blackbox_jaspr 0.0.1
blackbox_jaspr: ^0.0.1 copied to clipboard
Jaspr bindings for Blackbox (Observer + BoxProvider + ObservableFlowBox) with production-grade tracking.
blackbox_jaspr #
Jaspr bindings for blackbox.
This package adds UI integration primitives:
BoxProviderto expose boxes in the component treeBoxObserverto rebuild components when tracked boxes changeLocalStorageStoreas aPersistentStoreimplementation for browserlocalStorage
Features #
- Fine-grained rebuilds through tracked box reads
- Simple dependency access via
context.box<T>() - Persistence adapter for generated persistent boxes
- SSR-safe fallback: outside the browser,
LocalStorageStorebecomes in-memory
Installation #
dependencies:
blackbox_jaspr: ^0.0.1
blackbox: any
Basic Usage #
BoxProvider.multi(
boxes: [
counterBox,
profileBox,
],
child: const MyPage(),
);
class MyPage extends StatelessComponent {
const MyPage({super.key});
@override
Component build(BuildContext context) {
final counter = context.box<CounterBox>();
return BoxObserver(
builder: (_) {
final out = counter.output;
return Component.text('Count: ${out.value}');
},
);
}
}
LocalStorageStore #
No preload is required:
final store = LocalStorageStore();
In the browser the store persists primitive values to localStorage. Outside
the browser, it falls back to an in-memory store so SSR and tests stay
deterministic.
Observable FlowBox #
Wrap an existing FlowBox when you want BoxObserver tracking for flow state:
final flow = FlowBox.builder<MyFlowState>()
.on(counterBox, (value) => CounterReady(value))
.build(initial: const CounterIdle());
final observableFlow = flow.observable();
return BoxObserver(
builder: (_) => Component.text('${observableFlow.output.value}'),
);
Notes #
BoxProviderdoes not manage lifecycle of boxes. Dispose graphs/subscriptions manually where needed.BoxObservertracks boxes read duringbuilderexecution and rebuilds when those outputs change.- For
@observableboxes, tracking is injected byblackbox_codegen. Do not callBoxObserver.trackBox(...)manually from app code. ObservableFlowBoxis the manual adapter for ready-madeFlowBoxinstances. It forwardsdispose()to the wrapped flow.
License #
MIT