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

Abort share fetches if the current user has changed #118

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 21 additions & 2 deletions kano-share-feed/kano-share-feed.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@
type: String,
value: 'detailed'
},
/**
* Whether the feed has been populated with entries for the
* current settings
*/
populated: {
type: Boolean,
value: false
},
shares: {
type: Array,
value: () => {
Expand All @@ -204,7 +212,12 @@
//need to fire resize event to refresh scroller value
window.dispatchEvent(new Event('resize'));
},
_handleChanges () {
_handleChanges (current, previous) {
if (this.fetching) {
// If the component is already fetching data, set the flag
// to abort the current request and reset
this.resetRequired = true;
}
if (this.populated) {
this.reset();
}
Expand Down Expand Up @@ -236,6 +249,11 @@
fetch(this._getUrl(feedType) + '?' + queryString)
.then(r => r.json())
.then(r => {
// Abort the current request if a reset is required
if (this.resetRequired) {
this.reset();
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use a more sophisticated way to cancel the fetch() request? whatwg/fetch#27

To be honest I feel we should cancel/abort/defer this request even before we get a result, no?
If we have a fetching property, wouldn't be nice to have the promise somewhere so we could just abort it and replace with something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had a go at implementing cancelable promises in the PR for various other fixes: b547eff

This seems to fix the problem in a more elegant way, so I'll close this PR. We can always come back to this solution if things blow up in our faces.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIIIIIN!!!

}
if (r.entries.length) {
r.entries.forEach(share => {
if (share) {
Expand All @@ -249,11 +267,11 @@
}
});
this.set('page', r.next);
this.set('populated', true);
this.set('empty', false);
} else {
this.set('empty', true);
}
this.set('populated', true);
this.set('fetching', false);
this.$.threshold.clearTriggers();
});
Expand All @@ -265,6 +283,7 @@
this.set('populated', false);
this.set('shares', []);
this.set('page', 0);
this.set('resetRequired', false);
this.set('selectedShare', {});
this._loadMoreData();
},
Expand Down