Skip to content

Commit

Permalink
fix: use function reference to add & remove listener (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
billerr authored Mar 4, 2024
1 parent 180290e commit 151b863
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/lottie-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,7 @@ export class LottiePlayer extends LitElement {
// }

// Remove the attached Visibility API's change event listener.
document.removeEventListener("visibilitychange", () =>
this._onVisibilityChange()
);
document.removeEventListener("visibilitychange", this._onVisibilityChange);

// Destroy the animation instance and element
this.destroy();
Expand Down Expand Up @@ -599,9 +597,7 @@ export class LottiePlayer extends LitElement {

// Add listener for Visibility API's change event.
if (typeof document.hidden !== "undefined") {
document.addEventListener("visibilitychange", () =>
this._onVisibilityChange()
);
document.addEventListener("visibilitychange", this._onVisibilityChange);
}

// Setup lottie player
Expand Down Expand Up @@ -706,7 +702,7 @@ export class LottiePlayer extends LitElement {
/**
* Handle visibility change events.
*/
private _onVisibilityChange(): void {
private readonly _onVisibilityChange = (): void => {
if (document.hidden === true && this.currentState === PlayerState.Playing) {
this.freeze();
} else if (this.currentState === PlayerState.Frozen) {
Expand Down

0 comments on commit 151b863

Please sign in to comment.