Debouncing in TypeScript, v2

Matt Kenefick
Feb 4, 2022

--

This is a follow-up article to my previous one, Debouncing in TypeScript. It will be straight to the point about the revisions.

Mild changes to the previous version.

A couple household updates include:

  • Constructor doesn’t return bound function per TypeScript strict mode
  • Constructor doesn’t have a return type
  • Setting lastTrigger in constructor to avoid immediate execution

More significant updates include:

  • Static exec method so you don’t have to maintain a reference to the debouncer

You can use this class in this way:

The core piece here is the Debounce.exec(..., );

This example assumes that you have a symbol defined for each class instantiation which will provide a unique namespace for every Debounce instance. If you continually create new symbols, it will make new instances per call.

--

--

Matt Kenefick

Chief Product Engineer. Frontend, Backend, Systems, Electronics, 3D Printing, Photography.