Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
amk221 committed Mar 8, 2024
1 parent 805ab24 commit 0afb6e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions addon/components/infinite-scroller.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const { round } = Math;

export default class InfiniteScrollerComponent extends Component {
@tracked isLoading = false;
@tracked isScrollable = false;
@tracked scrollState = {};
@tracked lastScrollState = {};

debug;
scroller;
Expand Down Expand Up @@ -77,10 +78,14 @@ export default class InfiniteScrollerComponent extends Component {
}

_checkShouldLoadMore() {
const scrollState = this._getScrollState();
const shouldLoadMore = scrollState.reachedBottom && !this.isLoading;
this.scrollState = this._getScrollState();

this._debug({ ...scrollState, shouldLoadMore });
const shouldLoadMore = this.scrollState.reachedBottom && !this.isLoading;

this._debug({
...this.scrollState,
shouldLoadMore
});

if (shouldLoadMore) {
this.loadMore();
Expand All @@ -92,11 +97,9 @@ export default class InfiniteScrollerComponent extends Component {
return;
}

const scrollState = this._getScrollState();

this._debug({ ...scrollState });
this.scrollState = this._getScrollState();

this.isScrollable = scrollState.isScrollable;
this._debug(this.scrollState);
}

_debug(state) {
Expand Down Expand Up @@ -132,7 +135,7 @@ export default class InfiniteScrollerComponent extends Component {

get _api() {
return {
isScrollable: this.isScrollable,
isScrollable: this.scrollState.isScrollable,
isLoading: this.isLoading,
loadMore: this.loadMore
};
Expand All @@ -149,7 +152,7 @@ export default class InfiniteScrollerComponent extends Component {
<div
class="infinite-scroller"
data-loading="{{this.isLoading}}"
data-scrollable="{{this.isScrollable}}"
data-scrollable="{{this.scrollState.isScrollable}}"
...attributes
{{this.setScroller @element}}
>
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/infinite-scroller-test.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module('infinite-scroller', function (hooks) {
assert.dom('.infinite-scroller').exists('has an appropriate class name');
});

test('scrollable class', async function (assert) {
test('scrollable attr', async function (assert) {
assert.expect(2);

await render(<template>
Expand Down

0 comments on commit 0afb6e2

Please sign in to comment.