Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use function reference to add & remove listener #219

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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