Tags: disjukr/bunja
Tags
v3 (#29) ## Summary This PR introduces the v3 dependency graph model for Bunja. The main additions are `bunja.withSeed`, `bunja.will`, bunja refs, active optional dependency tracking, and `store.prebake`. Together they allow a bunja to declare possible dependencies statically while mounting only the dependency branch that is actually used by the first instance creation. ## What Changed ### Seeded bunjas - Added `bunja.withSeed(defaultSeed, init)`. - `seed` is creation-time data for the first matching bunja instance. - `seed` is not part of the bunja instance identity. - If an instance already exists, later seed values are ignored. - `store.get`, `useBunja`, `bunja.use`, and `bunja.will` can receive bunja refs with `seed`. ### Conditional dependencies - Added `bunja.will`. - `bunja.will(dep)` declares a possible bunja dependency and returns a thunk. - Only the called thunk becomes an active dependency and gets mounted. - The thunk can only be called during the same bunja init function that created it. - `bunja.use` and `bunja.will` must still be called unconditionally and in a stable order, similar to React’s Rules of Hooks. ### Scope value pairs - Bunja refs and `bunja.use`/`bunja.will` can provide scope value pairs. - The selected bunja and the provided scope value pair list must be static. - Dynamic `seed` values are allowed because they are not recorded in the dependency graph. - Scope value pairs are used to override scope values while resolving a dependency. ### Instance identity - Bunja instance ids now include active optional dependency ids. - This means a bunja can resolve to different instances depending on which `bunja.will` branch is actually selected. - Scopes used by active optional dependencies are reflected in the consuming bunja instance identity. - Inactive optional dependencies do not create or mount instances. ### Prebaking - Added `store.prebake`. - Prebake runs bunja init functions in a dry graph-collection mode. - It does not create ref-counted instances, mount dependencies, or run effects. - It is intended for devtools/debugging cases where optional `bunja.will` dependency graphs should be discovered ahead of time. - Root seed is intentionally not accepted by `store.prebake`; default seeds are used for deterministic graph collection. ### Graph metadata cleanup - Renamed `relatedScopes` to `requiredScopes`. - `relatedBunjas` is now derived from required and optional bunja dependencies. - Added explicit required/optional dependency tracking internally. - Added circular dependency guards for both normal `store.get` and `store.prebake`. ### Adapter updates - React adapter now accepts bunja refs in `useBunja`. - React 19 uses `React.use` for scoped context reads when available. - React 18 falls back to reading all bound contexts and requires scopes to be bound before rendering. - Solid adapter now accepts bunja refs in `useBunja`. ### Removed - Removed `bunja.fork`. - Scope overrides should now use `bunja.use(dep, scopeValuePairs)` or bunja refs.
PreviousNext