comrade.js

Debouncing vs throttling: when to use which

March 14 · 4 min read javascript

Both patterns limit how often a function runs, but they solve different problems. Debouncing waits for a pause in events before firing; throttling guarantees a steady execution rate regardless of how many events come in. A quick rule of thumb: use debounce for search-as-you-type inputs, and throttle for scroll or resize handlers.

Structured cloning without lodash

February 27 · 3 min read node

Modern runtimes ship structuredClone() natively, which handles circular references, Maps, Sets and typed arrays correctly — something JSON.parse(JSON.stringify(x)) has never been able to do. Worth checking before reaching for a dependency.

A minimal event bus in 20 lines

February 9 · 5 min read patterns

You don't always need a state management library. A tiny pub/sub built on a Map of listener arrays covers most cross-component communication needs in small to mid-sized apps, with zero bundle-size cost.

Why AbortController deserves more attention

January 22 · 3 min read fetch

Cancelling in-flight requests used to mean tracking booleans by hand. Now a single AbortController instance can cancel fetches, timers and event listeners together, which cleans up a lot of component-unmount logic.