Začetni commit projekta rezervacije

This commit is contained in:
Mark Poljanšek committed 2025-04-23 20:19:33 +02:00
commit 328731b32f
56062 files changed
+2485242

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
export { default } from "./useTimeout.js";
export { Timeout } from "./useTimeout.js";
+2
View File
@@ -0,0 +1,2 @@
export { default } from "./useTimeout.js";
export { Timeout } from "./useTimeout.js";
+11
View File
@@ -0,0 +1,11 @@
export declare class Timeout {
static create(): Timeout;
currentId: ReturnType<typeof setTimeout> | null;
/**
* Executes `fn` after `delay`, clearing any previously scheduled call.
*/
start(delay: number, fn: Function): void;
clear: () => void;
disposeEffect: () => () => void;
}
export default function useTimeout(): Timeout;
+35
View File
@@ -0,0 +1,35 @@
'use client';
import useLazyRef from "../useLazyRef/useLazyRef.js";
import useOnMount from "../useOnMount/useOnMount.js";
export class Timeout {
static create() {
return new Timeout();
}
currentId = null;
/**
* Executes `fn` after `delay`, clearing any previously scheduled call.
*/
start(delay, fn) {
this.clear();
this.currentId = setTimeout(() => {
this.currentId = null;
fn();
}, delay);
}
clear = () => {
if (this.currentId !== null) {
clearTimeout(this.currentId);
this.currentId = null;
}
};
disposeEffect = () => {
return this.clear;
};
}
export default function useTimeout() {
const timeout = useLazyRef(Timeout.create).current;
useOnMount(timeout.disposeEffect);
return timeout;
}