Timeout.js 709 B

1234567891011121314151617181920212223242526272829303132333435
  1. class Timeout {
  2. constructor(e, t, r=!0) {
  3. E(this, "_fn");
  4. E(this, "_delay");
  5. E(this, "_timeout");
  6. this._fn = e,
  7. this._delay = t,
  8. r && this.start()
  9. }
  10. get delay() {
  11. return this._delay
  12. }
  13. get isSet() {
  14. return !!this._timeout
  15. }
  16. setDelay(e) {
  17. this._delay = e
  18. }
  19. start() {
  20. this.isSet || (this._timeout = window.setTimeout(()=>{
  21. const e = this._fn;
  22. this.clear(),
  23. e()
  24. }
  25. , this._delay))
  26. }
  27. clear() {
  28. window.clearTimeout(this._timeout),
  29. this._timeout = void 0
  30. }
  31. reset() {
  32. this.clear(),
  33. this.start()
  34. }
  35. }