Skip to content

refactor: use AsyncResult accessors instead of manual result inspection#95

Merged
lucas-barake merged 2 commits into
mainfrom
refactor/async-result-accessors
Jul 10, 2026
Merged

refactor: use AsyncResult accessors instead of manual result inspection#95
lucas-barake merged 2 commits into
mainfrom
refactor/async-result-accessors

Conversation

@lucas-barake

Copy link
Copy Markdown
Owner

What

Replaces hand-rolled inspection of AsyncResult values in FormAtoms.ts with the accessors effect v4 already ships in effect/unstable/reactivity/AsyncResult:

  • displayErrorAtom: the manual _tag === "Failure" + Cause.findErrorOption + Schema.isSchemaError block collapses to Option.flatMap(AsyncResult.error(validationResult), Validation.extractFirstError). AsyncResult.error is exactly self._tag === "Failure" ? Cause.findErrorOption(self.cause) : Option.none(), and the validation atom's error channel is statically Schema.SchemaError, so the isSchemaError re-guard was redundant.
  • _tag === "Success"AsyncResult.isSuccess.
  • Raw .waiting reads (displayErrorAtom, isValidating, autoSubmitAtom, onBlurSubmitAtom) → AsyncResult.isWaiting.
  • Dropped the now-unused Cause import.

Behavior

No behavior change. Added one focused test locking the previously untested branch: a stored field-source error is hidden while validation is re-running (waiting), alongside the existing test covering the validation-success case.

Verification

  • pnpm check:types clean
  • pnpm vitest run: 302 tests passed (9 files)
  • pnpm lint clean

@lucas-barake
lucas-barake force-pushed the refactor/async-result-accessors branch from 3105b7f to 9c792a2 Compare July 10, 2026 02:38
@lucas-barake
lucas-barake merged commit 953fdf9 into main Jul 10, 2026
4 checks passed
@lucas-barake
lucas-barake deleted the refactor/async-result-accessors branch July 10, 2026 02:38
@github-actions github-actions Bot mentioned this pull request Jul 10, 2026
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