Debouncing in TypeScript, v2
This is a follow-up article to my previous one, Debouncing in TypeScript. It will be straight to the point about the revisions.
A couple household updates include:
- Constructor doesn’t return bound function per TypeScript strict mode
- Constructor doesn’t have a return type
lastTriggerin constructor to avoid immediate execution
More significant updates include:
execmethod 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
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.