debounce.ts 345 B

1234567891011121314
  1. // Based on underscore.js debounce()
  2. export default function debounce(func, wait) {
  3. let timeout;
  4. return function(this: any) {
  5. const context = this;
  6. const args = arguments;
  7. const later = () => {
  8. timeout = null;
  9. func.apply(context, args);
  10. };
  11. clearTimeout(timeout);
  12. timeout = setTimeout(later, wait);
  13. };
  14. }