Skip to content

Commit

Permalink
Merge pull request #5 from gokatz/fix-handle-destroy-state
Browse files Browse the repository at this point in the history
fix: component state issue
  • Loading branch information
gokatz authored Nov 13, 2018
2 parents 6860f34 + e02304d commit 97318df
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions addon/components/sloth-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default Component.extend({

if ('requestIdleCallback' in window) {
window.requestIdleCallback(() => {
this.send('loadMoreData')
this._loadMoreData();
}, {
/*
if requestIdleCallback is not fired withing the given `loadInterval`
Expand All @@ -74,7 +74,7 @@ export default Component.extend({

// fallback to setTimeout
setTimeout(() => {
this.send('loadMoreData')
this._loadMoreData();
}, loadInterval);
},

Expand All @@ -87,7 +87,7 @@ export default Component.extend({
let scrollElement = this.get('_scrollElement');
// start to load data on 2/3 scroll
if (scrollElement.scrollTop > (scrollElement.scrollHeight / 3) * 2) {
this.send('loadMoreData');
this._loadMoreData();
}
},

Expand Down Expand Up @@ -139,19 +139,24 @@ export default Component.extend({
this._super(...arguments);
},

_loadMoreData() {
if (!this.get('isDestroyed')) {
this.send('loadMoreData')
}
},

actions: {
loadMoreData() {

let {
data: entireData = [],
loadCount,
dataForCurrentView = [] ,
isDestroyed
} = this.getProperties('data', 'loadCount', 'dataForCurrentView', 'isDestroyed');
} = this.getProperties('data', 'loadCount', 'dataForCurrentView');

let isDoneRenderingList = dataForCurrentView.length === entireData.length;

if (isDestroyed || isDoneRenderingList) {
if (isDoneRenderingList) {
return;
}

Expand Down

0 comments on commit 97318df

Please sign in to comment.