debounce input change

This commit is contained in:
iamBadgers committed 2025-08-17 12:57:39 -07:00
1 parent 468bf24214
commit ec98fb9975
3 files changed
+24 -5

No files matched your search

+1
View File
@@ -3,3 +3,4 @@ export const MODULE_ID = "rush-character-archive-foundry-module";
export const URI_SETTING_NAME = "uri_setting"; export const URI_SETTING_NAME = "uri_setting";
export const API_KEY_NAME = "api_key"; export const API_KEY_NAME = "api_key";
+10 -5
View File
@@ -54,7 +54,7 @@ export class CharacterArchiver extends Application {
html html
.find(".character-handle") .find(".character-handle")
.on("change", this.handleChange.bind(this)); .on("input", this.handleChange.bind(this));
} }
private async archiveButton() { private async archiveButton() {
@@ -80,11 +80,16 @@ export class CharacterArchiver extends Application {
this.client.createCharacter(request); this.client.createCharacter(request);
} }
timeout: NodeJS.Timeout | undefined;
private async handleChange(e: Event) { private async handleChange(e: Event) {
console.log(e.target); clearTimeout(this.timeout);
const target = e.target as HTMLTextAreaElement; this.timeout = setTimeout(() => {
this.data.handle = target.value; console.log(e.target);
console.log(this.data.handle); const target = e.target as HTMLTextAreaElement;
this.data.handle = target.value;
console.log(this.data.handle);
}, 500);
} }
} }
+13
View File
@@ -3,3 +3,16 @@ export const MODULE_ID = "rush-character-archive-foundry-module";
export const URI_SETTING_NAME = "uri_setting"; export const URI_SETTING_NAME = "uri_setting";
export const API_KEY_NAME = "api_key"; export const API_KEY_NAME = "api_key";
export function debounce<P extends any[]>(
callback: (...args: P) => any,
time: number
): (...args: P) => void {
let timer: NodeJS.Timeout | undefined;
return function (this: any, ...args: P) {
clearTimeout(timer);
timer = setTimeout(() => callback.apply(this, args), time);
return timer;
}
}