This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #880 from adfinis/fix-analytics-loading-loop
fix: analytics loading loop
- Loading branch information
Showing
4 changed files
with
19 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,36 @@ | ||
import Component from "@ember/component"; | ||
import { get } from "@ember/object"; | ||
import classic from "ember-classic-decorator"; | ||
import { action } from "@ember/object"; | ||
import Component from "@glimmer/component"; | ||
import { tracked } from "@glimmer/tracking"; | ||
|
||
@classic | ||
class InViewportComponent extends Component { | ||
rootSelector = "body"; | ||
rootMargin = 0; | ||
export default class InViewport extends Component { | ||
@tracked rootSelector = "body"; | ||
@tracked rootMargin = 0; | ||
_observer = null; | ||
|
||
didInsertElement(...args) { | ||
super.didInsertElement(...args); | ||
|
||
@action | ||
registerObserver(element) { | ||
const observer = new IntersectionObserver( | ||
([{ isIntersecting }]) => { | ||
if (isIntersecting) { | ||
return (get(this, "on-enter-viewport") ?? (() => {}))(); | ||
return (this.args["on-enter-viewport"] ?? (() => {}))(); | ||
} | ||
|
||
return (get(this, "on-exit-viewport") ?? (() => {}))(); | ||
return (this.args["on-exit-viewport"] ?? (() => {}))(); | ||
}, | ||
{ | ||
root: document.querySelector(this.rootSelector), | ||
rootMargin: `${this.rootMargin}px`, | ||
} | ||
); | ||
|
||
this.set("_observer", observer); | ||
this._observer = observer; | ||
|
||
// eslint-disable-next-line ember/no-observers | ||
observer.observe(this.element); | ||
observer.observe(element); | ||
} | ||
|
||
willDestroyElement(...args) { | ||
super.willDestroyElement(...args); | ||
|
||
this._observer.disconnect(); | ||
willDestroy(...args) { | ||
super.willDestroy(...args); | ||
this._observer?.disconnect(); | ||
} | ||
} | ||
|
||
export default InViewportComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
{{yield}} | ||
<div | ||
{{did-insert this.registerObserver}}>{{yield}}</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters