Skip to content

Commit

Permalink
chore: debounce event trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
anfibiacreativa committed Nov 4, 2023
1 parent a7a3b63 commit 26d8053
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/chat-component/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,15 @@ export class ChatComponent extends LitElement {
this.handleOnMustScroll();
});
}

// debounce dispatching must-scroll event
debounceDispatchMustScrollEvent(): void {
let timeout: any = 0;
clearTimeout(timeout);
timeout = setTimeout(() => {
this.dispatchEvent(mustScrollEvent);
}, 500);
}
// handle must scroll event
handleOnMustScroll(): void {
const footer = this.shadowRoot?.querySelector('#chat-list-footer') as HTMLElement;
if (footer) {
Expand Down Expand Up @@ -370,7 +378,7 @@ export class ChatComponent extends LitElement {
</ol>`,
);
}
this.dispatchEvent(mustScrollEvent);
this.debounceDispatchMustScrollEvent();
return entries;
}

Expand All @@ -396,7 +404,6 @@ export class ChatComponent extends LitElement {
</ol>
`;
}
this.dispatchEvent(mustScrollEvent);
return '';
}

Expand All @@ -423,7 +430,6 @@ export class ChatComponent extends LitElement {
</div>
`;
}
this.dispatchEvent(mustScrollEvent);
return '';
}

Expand Down

0 comments on commit 26d8053

Please sign in to comment.