Skip to content

Commit

Permalink
Format callback
Browse files Browse the repository at this point in the history
  • Loading branch information
leonyu committed Oct 12, 2024
1 parent aea2839 commit 9f5b0a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/AsyncUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type Func<TInput extends unknown[], TOutput> = (...args: TInput) => TOutput;
type Func<TInput extends never[], TOutput> = (...args: TInput) => TOutput;

export function debounce<T extends Func<unknown[], void>>(
export function debounce<T extends Func<never[], void>>(
func: T,
wait: number,
): Func<Parameters<T>, void> {
Expand Down
13 changes: 7 additions & 6 deletions src/QRView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ 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 {
this.updateTextBox(text);
void this.updateQRCode(text);
}

debouncedUpdateInput = debounce((text: string) => {
this.updateInput(text);
}, 50);

private async updateQRCode(text: string): Promise<void> {
this.qrSvg.innerHTML = await toString(text || EMPTY_QRCODE_SEGMENT, {
type: 'svg',
Expand Down

0 comments on commit 9f5b0a4

Please sign in to comment.