Skip to content

Commit

Permalink
pkp/pkp-lib#8803 Fix problem with request callback context
Browse files Browse the repository at this point in the history
  • Loading branch information
NateWr committed Mar 20, 2023
1 parent 997480b commit bcc277c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/components/Composer/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,8 @@ export default {
return;
}
this.isSearching = true;
this.latestSearchRequest = $.pkp.classes.Helper.uuid();
const uuid = $.pkp.classes.Helper.uuid();
this.latestSearchRequest = uuid;
this.showSearchResultCount = 10;
$.ajax({
Expand All @@ -902,21 +903,21 @@ export default {
_uuid: this.latestSearchRequest,
error: function (r) {
// Only process latest request response
if (this.latestSearchRequest !== this._uuid) {
if (this.latestSearchRequest !== uuid) {
return;
}
this.ajaxErrorCallback(r);
},
success: function (r) {
// Only process latest request response
if (this.latestSearchRequest !== this._uuid) {
if (this.latestSearchRequest !== uuid) {
return;
}
this.searchResults = r.items;
},
complete() {
// Only process latest request response
if (this.latestSearchRequest !== this._uuid) {
if (this.latestSearchRequest !== uuid) {
return;
}
this.isSearching = false;
Expand Down
10 changes: 5 additions & 5 deletions src/mixins/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export default {
// most recent get request. When we receive the response, we
// can check that the response matches the most recent get request, and
// discard responses that are outdated.
this.latestGetRequest = $.pkp.classes.Helper.uuid();
const uuid = $.pkp.classes.Helper.uuid();
this.latestGetRequest = uuid;

$.ajax({
url: this.apiUrl,
Expand All @@ -100,24 +101,23 @@ export default {
count: this.count,
offset: this.offset,
},
_uuid: this.latestGetRequest,
error: function (r) {
// Only process latest request response
if (this.latestGetRequest !== this._uuid) {
if (this.latestGetRequest !== uuid) {
return;
}
this.ajaxErrorCallback(r);
},
success: function (r) {
// Only process latest request response
if (this.latestGetRequest !== this._uuid) {
if (this.latestGetRequest !== uuid) {
return;
}
this.setItems(r.items, r.itemsMax);
},
complete() {
// Only process latest request response
if (this.latestGetRequest !== this._uuid) {
if (this.latestGetRequest !== uuid) {
return;
}
this.isLoading = false;
Expand Down

0 comments on commit bcc277c

Please sign in to comment.