Skip to content

test(data): document composition→derive pattern for resource reads#148

Merged
krisnye merged 2 commits into
mainfrom
krisnye/derive-resource-doctest
Jul 16, 2026
Merged

test(data): document composition→derive pattern for resource reads#148
krisnye merged 2 commits into
mainfrom
krisnye/derive-resource-doctest

Conversation

@krisnye

@krisnye krisnye commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Adds a db.derive unit test documenting the migration from Observe composition to db.derive for resource reads.

// before
const sum = Observe.withMap(
  Observe.fromProperties({ x: db.observe.resources.x, y: db.observe.resources.y }),
  ({ x, y }) => x + y,
);

// after
const sum = db.derive(db => db.resources.x + db.resources.y);

The test asserts the derive:

  • emits the initial sum on subscribe, and
  • recomputes when either resource changes (both reads are auto-tracked — no hand-listed inputs).

The callback param is intentionally named db to shadow the outer db, so a read cannot bind the outer (full) db and silently escape dependency tracking.

Test-only; no version bump.

🤖 Generated with Claude Code

krisnye and others added 2 commits July 15, 2026 16:32
Add a db.derive unit test that derives a value from two resources
(`db.derive(db => db.resources.x + db.resources.y)`) and asserts it recomputes
when either resource changes — the auto-tracked replacement for
`Observe.withMap(Observe.fromProperties({ x, y }), ({ x, y }) => x + y)`. The
callback param is intentionally named `db` to shadow the outer db so a read
cannot bind the outer (full) db and escape dependency tracking.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A derive that conditionally reads `b` (only while `a > 0`) must stop re-running
on `b` changes once `a` flips and the next run records deps without `b` —
verifying each run replaces the observed set rather than accumulating it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@krisnye
krisnye merged commit b2f47ea into main Jul 16, 2026
4 checks passed
@krisnye
krisnye deleted the krisnye/derive-resource-doctest branch July 16, 2026 00:50
krisnye added a commit that referenced this pull request Jul 16, 2026
Resolve observe-derive.test.ts: keep both #148's tests (resource-sum doc +
dependency-set-rebuild) and this branch's inputs-overload tests. No behavioral
overlap; the shared makeSource helper + Observe import auto-merged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant