Grabbed dndbeyond's source code
``` ~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js ```
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
'use client';
|
||||
|
||||
import useLazyRef from '../useLazyRef/useLazyRef';
|
||||
import useOnMount from '../useOnMount/useOnMount';
|
||||
export class Timeout {
|
||||
constructor() {
|
||||
this.currentId = null;
|
||||
this.clear = () => {
|
||||
if (this.currentId !== null) {
|
||||
clearTimeout(this.currentId);
|
||||
this.currentId = null;
|
||||
}
|
||||
};
|
||||
this.disposeEffect = () => {
|
||||
return this.clear;
|
||||
};
|
||||
}
|
||||
static create() {
|
||||
return new Timeout();
|
||||
}
|
||||
/**
|
||||
* Executes `fn` after `delay`, clearing any previously scheduled call.
|
||||
*/
|
||||
start(delay, fn) {
|
||||
this.clear();
|
||||
this.currentId = setTimeout(() => {
|
||||
this.currentId = null;
|
||||
fn();
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
export default function useTimeout() {
|
||||
const timeout = useLazyRef(Timeout.create).current;
|
||||
useOnMount(timeout.disposeEffect);
|
||||
return timeout;
|
||||
}
|
||||
Reference in New Issue
Block a user