This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.

Store

~import std/store

Koru Standard Library: Reactive Stores

store.kz · 11 tors

Koru Standard Library: Reactive Stores · 66 more lines
Koru Standard Library: Reactive Stores Application state as a compiled-reactivity substrate. The FULL design — 9 rulings, adversary-stamped theses, the open queue — lives in tests/regression/600_STDLIB/690_STORE/DESIGN.md (delete-when-pinned). The pins (690_001..008) are the acceptance tests; this file grows until they green, rung by rung. THE SPINE (ruled 2026-07-04): - A store is COMPTIME-NAMED and second-class (ruling 9): never a value, never passed, never nested. `create(game) { ... }` declares name + shape + seed; anyone anywhere links by name. - `stored { game.field: expr }` is the SOLE write path. - Subscriptions (`watch`) compile INTO the write path — tap-style, producer owns the guard, NO runtime registry (ruling 7). - Ruling (f): all writes route through ONE centralizing write-subflow per store; watches/interceptors/guards splice there ONCE. - Writes interleave, never overlap: write + full cascade is the atomicity unit ((h) lean); birth is not a write (O9 lean — the seed is stored in memory, never dispatched as an event). RUNG ONE — COMPLETE (690_001-004 green runners, 690_006 green designed rejection; SHOWN 2026-07-05). The (f) architecture: `create` is the coordinator. Per store it appends FIVE units: 1. The module-scope typed cell (capture's @Type builder, host_line). 2. An APPLY event — one terminal branch per field, announcing what was written (`| entities i64`; with an `updated` interceptor the payload is `{ old, new }` — the (c) usage-synthesis lean). 3. The apply |zig proc — switch on the comptime-constant field index, write the cell, return the field's branch with the new value. (kernel's raw-Zig generated-proc precedent.) 4. The WRITE event — the store's sole write surface, void. 5. The write event's implementing FLOW — head invokes apply; its continuation arms ARE the transplanted interceptor+watch branches, interceptors sequenced first ((h): watches observe settled state), guards riding as arm conditions (producer owns the if). THIS is the ruling-(f) centralizing write-subflow: bodies splice here ONCE; the atomicity lock and T8 backend cells will live in this body. A nested `stored` inside an interceptor body compiles into a call into the OTHER store's write-subflow — the cascade is ordinary calls through generated subflows, no runtime registry. `stored` rewrites each write site into a plain invocation of the write event — an ordinary flow, emitted inside a function like any call. `watch` sites run the transplant-purity check (ruling (a): free names ⊆ own bindings ∪ comptime-known — koru-level diagnostic, 690_006) and self-erase once the coordinator has spliced their bodies. STILL WALLED (loud, never silent — KORU047 doctrine): - Multiple watches on one field — needs taps' sequencing splice. - Multi-field `stored` blocks — the (i) chain-envelope, rung two. - Mixing `updated {old,new}` with field-level consumers on one store. - Guarded watch on a field that also has interceptors. - Nested (mid-flow) watch splicing; watch-before-create source order. - Non-i64 fields; guarded interceptors; `inserted`/`removed` (rung 2). ARCHITECTURE NOTES: - Generated decls follow kernel's precedent exactly (event_decl + proc_decl with raw-Zig body, appended as top-level items; the emitter finds impl_of flows by scanning items at emission time). - Watch collection is kernel's findShapeSource pattern: the transform receives *const Program and walks items for `std/store:watch(name)` flows. Source order: create must precede its watches (loud wall otherwise — the walker transforms in program order, and the coordinator must still be able to see untransformed watch bodies). - Validation happens IN the transforms (loud refusal), not the shape checker — checkers run after transforms (capture precedent).

new

keywordcomptimetransform koru_std/store.kz:813

stored

keywordcomptimetransform koru_std/store.kz:6856

default

keywordcomptimetransformpre koru_std/store.kz:7729

watch

keywordcomptimetransform koru_std/store.kz:7800

insert

keywordcomptimetransform koru_std/store.kz:8095

rule

keywordcomptimetransformclaims_descendants koru_std/store.kz:8485

query

keywordcomptimetransformclaims_descendants koru_std/store.kz:8626

preorder

keywordcomptimetransformclaims_descendants koru_std/store.kz:9837

take

keywordcomptimetransform koru_std/store.kz:9940

clear

keywordcomptimetransform koru_std/store.kz:10110

stripe

keywordcomptimetransform koru_std/store.kz:10198