Skip to content

feat(data-lit-todo): drag-reorder via useDragGenerator + dragTodo action - #199

Merged
krisnye merged 1 commit into
mainfrom
krisnye/use-drag-generator
Sep 15, 2026
Merged

krisnye merged 1 commit into
mainfrom
krisnye/use-drag-generator

Conversation

@krisnye

@krisnye krisnye commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds the missing textbook example of the useDragGenerator + async-generator-to-transaction pattern to the data-lit-todo sample. Previously the sample had no correct demonstration of driving a multi-frame transaction from useDragGenerator.

The flow is now:

  • todo-row-element calls useDragGenerator, which hands the raw DragState stream to…
  • a new dragTodo action, which maps each yielded drag frame to the dragTodo transaction's args and drives the transaction with that mapped async generator, so…
  • the dragTodo transaction commits every frame (live offsets + final drop) as one coalesced, undoable step.

Details

  • New action-database/actions/drag-todo.ts — maps move→live offset, end→final drop (finalIndex), cancel{ dragPosition: null } (abandon with no reorder). Row height is passed in as a plain arg, never imported, so services/ keeps its strict independence from ui/.
  • drag-todo transaction input widened to dragPosition: number | null so a cancelled gesture resets cleanly.
  • todo-row-element switched from useDragTransaction to useDragGenerator; arg-shaping now lives in the action per the container-element rule (no shape-building in a callback).
  • reorder-todo action doc updated to reflect the new drag path.

Test plan

  • New drag-todo.test.ts unit test covers both the reorder (move→end) and the cancel (move→cancel, no reorder) paths.
  • Full data-lit-todo suite passes (109 tests, incl. conformance).
  • Whole-monorepo typecheck (cleared tsbuildinfo) and lint pass; bundled build succeeds (no TLA deadlock).
  • Verified in-browser: dragging a row reorders it correctly; a mid-drag cancel snaps the row back with no reorder and no console errors.

🤖 Generated with Claude Code

…dragTodo action

Replaces the todo row's useDragTransaction with the useDragGenerator hook: it
hands the raw DragState stream to a new dragTodo action, which maps each frame
to the dragTodo transaction's args and drives the transaction with the mapped
async generator. This is the textbook useDragGenerator → action → multi-frame
transaction pattern. The action maps drag→args (row height passed in as data,
never imported from ui/); a cancelled gesture yields dragPosition: null to
abandon the drag with no reorder. Covered by a dragTodo action unit test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@krisnye
krisnye merged commit ef233b0 into main Sep 15, 2026
3 checks passed
@krisnye
krisnye deleted the krisnye/use-drag-generator branch September 15, 2026 16:14
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