diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2022-05-19 04:46:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-19 04:46:12 +0300 |
commit | 742071ed81919ebb745f7a735b03a84c26a83b03 (patch) | |
tree | 07486606f7563700ab78665a2262ec33f62c4766 /plugins/CoreHome/vue/src | |
parent | f17af4c1b8811467962137163e28719831604066 (diff) |
[Vue] add utility function for pattern that issues a single AJAX request at a time (#19239)
* add utility function for pattern that issues a single AJAX request at a time (aborting the previous if in progress)
* make sure to pass abortController as option
Diffstat (limited to 'plugins/CoreHome/vue/src')
-rw-r--r-- | plugins/CoreHome/vue/src/AjaxHelper/AjaxHelper.ts | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/plugins/CoreHome/vue/src/AjaxHelper/AjaxHelper.ts b/plugins/CoreHome/vue/src/AjaxHelper/AjaxHelper.ts index 610ede1863..61a3aa7c09 100644 --- a/plugins/CoreHome/vue/src/AjaxHelper/AjaxHelper.ts +++ b/plugins/CoreHome/vue/src/AjaxHelper/AjaxHelper.ts @@ -266,7 +266,36 @@ export default class AjaxHelper<T = any> { // eslint-disable-line postParams: any = {}, options: AjaxOptions = {}, ): Promise<R> { - return this.fetch<R>(params, { ...options, postParams }); + return AjaxHelper.fetch<R>(params, { ...options, postParams }); + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static oneAtATime<R = any>( + method: string, + options?: AjaxOptions, + ): (params: QueryParameters, postParams?: QueryParameters) => Promise<R> { + let abortController: AbortController|null = null; + + return (params: QueryParameters, postParams?: QueryParameters) => { + if (abortController) { + abortController.abort(); + } + + abortController = new AbortController(); + return AjaxHelper.post<R>( + { + ...params, + method, + }, + postParams, + { + ...options, + abortController, + }, + ).finally(() => { + abortController = null; + }); + }; } constructor() { |