debounce input change
This commit is contained in:
@@ -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";
|
||||||
|
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
clearTimeout(this.timeout);
|
||||||
|
this.timeout = setTimeout(() => {
|
||||||
console.log(e.target);
|
console.log(e.target);
|
||||||
const target = e.target as HTMLTextAreaElement;
|
const target = e.target as HTMLTextAreaElement;
|
||||||
this.data.handle = target.value;
|
this.data.handle = target.value;
|
||||||
console.log(this.data.handle);
|
console.log(this.data.handle);
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user