Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #880 from adfinis/fix-analytics-loading-loop
Browse files Browse the repository at this point in the history
fix: analytics loading loop
  • Loading branch information
derrabauke authored Mar 22, 2023
2 parents 543327c + 918dcc9 commit 25bb3f6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/analysis/index/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export default class AnalysisController extends Controller.extend(
@tracked totalTime = moment.duration();
@tracked totalItems = A();
@tracked selectedReportIds;
@tracked _dataCache = A();

@tracked user;
@tracked reviewer;
Expand Down Expand Up @@ -194,7 +195,6 @@ export default class AnalysisController extends Controller.extend(
}

setup() {
this._dataCache = A();
this.selectedReportIds = A();

this.prefetchData.perform();
Expand Down
35 changes: 15 additions & 20 deletions app/components/in-viewport/component.js
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;
3 changes: 2 additions & 1 deletion app/components/in-viewport/template.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
{{yield}}
<div
{{did-insert this.registerObserver}}>{{yield}}</div>
2 changes: 1 addition & 1 deletion tests/integration/components/in-viewport/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module("Integration | Component | in viewport", function (hooks) {
await render(hbs`
<div class="parent" style="heigth: 20px; overflow: scroll;">
<div class="child" style="heigth: 2000px;">
{{#in-viewport}}test{{/in-viewport}}
<InViewport>test</InViewport>
</div>
</div>
`);
Expand Down

0 comments on commit 25bb3f6

Please sign in to comment.