Skip to content

Add throttle() and keep this in debounce() - #81

Merged
carlrafting merged 2 commits into
devfrom
claude/project-thread-cguq0j
Dec 1, 2026
Merged

carlrafting merged 2 commits into
devfrom
claude/project-thread-cguq0j

Conversation

@carlrafting

@carlrafting carlrafting commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Requested by Carl · project thread

Adds throttle(fn, interval = 100) to dom/utils.js, next to debounce().

  • The first call runs right away.
  • Calls inside the interval collapse into one trailing call with the latest arguments, so the last call is never lost.
  • It keeps the caller's this, so it works as a method or on a handleEvent object.

Also fixes debounce() so it passes the caller's this to fn (it used to pass the debounced wrapper), for both the trailing and the asap call.

Neither function is exported from dom/main.js yet. Exporting them is a separate decision.

Tests

Six new tests in dom/utils.test.ts: four for throttle() (leading call, trailing call, interval reset, this) and two for debounce()'s this. deno test, deno check with checkJs, deno lint and deno fmt --check pass on the two files.

https://claude.ai/code/session_01PsQ2rEfRCb5esUCN5whWoy


Generated by Claude Code

Runs the first call right away, then at most once per interval, with
one trailing call that gets the latest arguments. Keeps the caller's
this, so it works on handleEvent objects and methods.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PsQ2rEfRCb5esUCN5whWoy
@carlrafting carlrafting self-assigned this Nov 30, 2026

Copy link
Copy Markdown
Owner Author

The Workers Builds: vanillapod check failure isn't from this PR. The same check also fails on the current dev head (b2e4b97), and this PR only changes dom/utils.js and its tests, which the site build doesn't depend on. The build log is in the Cloudflare dashboard, which I can't open from here, so I can't see the cause.


Generated by Claude Code

debounce() called fn with the debounced wrapper as this, so it broke
on methods and handleEvent objects. Pass the caller's this instead,
for both the trailing and the asap call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PsQ2rEfRCb5esUCN5whWoy
@carlrafting carlrafting changed the title Add throttle() to dom utils Add throttle() and keep this in debounce() Nov 30, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

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

View logs ↗
9f1e726 2026-11-30T19:47:58.690Z View logs ↗

@carlrafting
carlrafting merged commit f0441bd into dev Dec 1, 2026
2 of 3 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.

2 participants