From bcc277cf5d30629bda8c977c89a1381fca50540b Mon Sep 17 00:00:00 2001 From: Nate Wright Date: Mon, 20 Mar 2023 17:53:25 +0000 Subject: [PATCH] pkp/pkp-lib#8803 Fix problem with request callback context --- src/components/Composer/Composer.vue | 9 +++++---- src/mixins/fetch.js | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/Composer/Composer.vue b/src/components/Composer/Composer.vue index 57039fb6e..39328d6cd 100644 --- a/src/components/Composer/Composer.vue +++ b/src/components/Composer/Composer.vue @@ -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({ @@ -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; diff --git a/src/mixins/fetch.js b/src/mixins/fetch.js index 69e66f3f0..e1d737489 100644 --- a/src/mixins/fetch.js +++ b/src/mixins/fetch.js @@ -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, @@ -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;