Jesus sucks

This commit is contained in:
2024-12-17 13:23:11 -08:00
parent 3a3382ffff
commit b2dbf46d28
13060 changed files with 1310035 additions and 1 deletions

View File

@@ -0,0 +1,2 @@
export { default } from './useTimeout';
export { Timeout } from './useTimeout';

View File

@@ -0,0 +1,48 @@
'use client';
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import useLazyRef from '../useLazyRef/useLazyRef';
import useOnMount from '../useOnMount/useOnMount';
export var Timeout = /*#__PURE__*/function () {
function Timeout() {
var _this = this;
_classCallCheck(this, Timeout);
this.currentId = null;
this.clear = function () {
if (_this.currentId !== null) {
clearTimeout(_this.currentId);
_this.currentId = null;
}
};
this.disposeEffect = function () {
return _this.clear;
};
}
_createClass(Timeout, [{
key: "start",
value:
/**
* Executes `fn` after `delay`, clearing any previously scheduled call.
*/
function start(delay, fn) {
var _this2 = this;
this.clear();
this.currentId = setTimeout(function () {
_this2.currentId = null;
fn();
}, delay);
}
}], [{
key: "create",
value: function create() {
return new Timeout();
}
}]);
return Timeout;
}();
export default function useTimeout() {
var timeout = useLazyRef(Timeout.create).current;
useOnMount(timeout.disposeEffect);
return timeout;
}