Skip to content

One wiring helper for every part 1 widget - #13

Merged
devmtnaing merged 1 commit into
mainfrom
widget-helper
Sep 28, 2026
Merged

devmtnaing merged 1 commit into
mainfrom
widget-helper

Conversation

@devmtnaing

@devmtnaing devmtnaing commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

This is the duplicate-code follow-up from the codebase review. All 46 part 1 widgets ended with the same plumbing:

  • a click listener for the preset chips
  • a keydown listener that repeated the cell click for Enter and Space
  • onLangChange(render) and render()

wireWidget(host, { render, choose }) in kit.js now does all of that, and each lesson keeps only what is its own.

wireWidget(host, { render, choose: (i) => { state.set = i; state.sel = 0; } });
  • 46 lessons now use it, and 15 keydown handlers that repeated a click are gone. The diff removes about 460 lines and adds about 190.
  • Enter and Space dispatch a click event instead of calling .click(). course-schedule's course nodes are SVG, and SVG elements have no click().
  • A widget can handle a key its own way by calling preventDefault(), and wireWidget leaves that key alone. valid-anagram does this so focus follows the moved letter.
  • Language changes call render() with no argument. Previously, valid-anagram's render(focusIndex) could be handed the language code.

Checked

  • Widget snapshots before and after: a Playwright script records each widget's HTML, label, focused element and URL after clicking every chip, clicking cells, pressing Enter and Space on cells, and switching language both ways. Math.random is seeded so shuffles repeat. All 509 snapshots across 46 lessons are identical to the build before this change. Only course-schedule differed in the first run, which is how the SVG .click() problem turned up.
  • npm run check: 46 lessons, 0 failures.
  • npm run audit: passed, 46 pages.
  • The lesson-kit reference and CONTRIBUTING.md describe wireWidget.

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 1b182848-ba17-4d3a-b6a9-c5f9e7bb03bf


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ 61c1885 2026-09-28T09:23:38.200Z Visit the dashboard ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ bf60286 2026-09-28T09:18:32.772Z Visit the dashboard ↗

Every widget ended with the same plumbing: a click listener for the preset
chips, a keydown listener repeating its cell click for Enter and space, then
onLangChange(render) and render(). wireWidget(host, { render, choose }) in
kit.js does all of it; a lesson keeps only what is its own.

- 46 widgets move to it; 15 keydown handlers that repeated a click go away
- Enter/space dispatches a click event rather than calling .click(), which
  SVG nodes (course-schedule's graph) lack
- a widget that handles a key its own way calls preventDefault() and is left
  alone: valid-anagram keeps focus following the moved letter
- language changes call render() with no argument, so a render that takes
  a focus index (valid-anagram) is no longer handed the language code
@devmtnaing
devmtnaing merged commit c65c0a4 into main Sep 28, 2026
101 of 102 checks passed
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