From 9f5b0a4efd1ca6f5274387df525630bb4319359a Mon Sep 17 00:00:00 2001 From: Leon Yu Date: Fri, 11 Oct 2024 21:41:24 -0400 Subject: [PATCH] Format callback --- src/AsyncUtils.ts | 4 ++-- src/QRView.ts | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/AsyncUtils.ts b/src/AsyncUtils.ts index a53b5fc..2050317 100644 --- a/src/AsyncUtils.ts +++ b/src/AsyncUtils.ts @@ -1,6 +1,6 @@ -type Func = (...args: TInput) => TOutput; +type Func = (...args: TInput) => TOutput; -export function debounce>( +export function debounce>( func: T, wait: number, ): Func, void> { diff --git a/src/QRView.ts b/src/QRView.ts index f1bb8b4..f6ed29d 100644 --- a/src/QRView.ts +++ b/src/QRView.ts @@ -15,12 +15,9 @@ export default class QRView { this.qrSvg = document.createElement('div'); container.appendChild(this.qrSvg); this.updateInput(''); - this.qrText.addEventListener( - 'input', - debounce(() => { - this.updateInput(this.qrText.value); - }, 50), - ); + this.qrText.addEventListener('input', () => { + this.debouncedUpdateInput(this.qrText.value); + }); } updateInput(text: string): void { @@ -28,6 +25,10 @@ export default class QRView { void this.updateQRCode(text); } + debouncedUpdateInput = debounce((text: string) => { + this.updateInput(text); + }, 50); + private async updateQRCode(text: string): Promise { this.qrSvg.innerHTML = await toString(text || EMPTY_QRCODE_SEGMENT, { type: 'svg',