Skip to content
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
79cfe4e
remove rxjs from http in devextreme-angular
GoodDayForSurf Mar 5, 2026
378ec64
Merge branch '26_1' into 26_1_rxjs_remove
GoodDayForSurf Mar 5, 2026
031d232
remove rxjs from http in devextreme-angular
GoodDayForSurf Mar 5, 2026
75d88c9
Merge branch '26_1_rxjs_remove' of https://github.com/GoodDayForSurf/…
GoodDayForSurf Mar 5, 2026
26a7bc3
remove rxjs from http in devextreme-angular
GoodDayForSurf Mar 5, 2026
aee4b28
Merge branch '26_1' into 26_1_rxjs_remove
GoodDayForSurf Mar 5, 2026
8dc2f17
remove rxjs from http in devextreme-angular
GoodDayForSurf Mar 5, 2026
66b3b4d
Merge branch '26_1_rxjs_remove' of https://github.com/GoodDayForSurf/…
GoodDayForSurf Mar 5, 2026
1c5eb78
Merge branch '26_1' of https://github.com/DevExpress/DevExtreme into …
GoodDayForSurf Mar 5, 2026
87f98db
remove rxjs from http in devextreme-angular
GoodDayForSurf Mar 5, 2026
3f047fa
Merge branch '26_1' into 26_1_rxjs_remove
GoodDayForSurf Mar 6, 2026
f8a76c5
Merge branch '26_1' into 26_1_rxjs_remove
GoodDayForSurf Mar 6, 2026
662998d
Merge branch '26_1' into 26_1_rxjs_remove
GoodDayForSurf Mar 7, 2026
34461e6
Merge branch '26_1' into 26_1_rxjs_remove
GoodDayForSurf Mar 9, 2026
8a32c81
remove rxjs from http in devextreme-angular
GoodDayForSurf Mar 9, 2026
333b8e8
Merge branch '26_1_rxjs_remove' of https://github.com/GoodDayForSurf/…
GoodDayForSurf Mar 9, 2026
96feee1
Merge branch '26_1' into 26_1_rxjs_remove
GoodDayForSurf Mar 10, 2026
40610b0
Merge branch '26_1' into 26_1_rxjs_remove
GoodDayForSurf Mar 10, 2026
2e7aab2
Merge branch '26_1' into 26_1_rxjs_remove
GoodDayForSurf Mar 10, 2026
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
72 changes: 55 additions & 17 deletions packages/devextreme-angular/src/http/ajax.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {
HttpClient, HttpEventType, HttpParams, HttpEvent, HttpErrorResponse, HttpResponse,
HttpClient,
HttpEventType,
HttpParams,
HttpEvent,
HttpErrorResponse,
HttpResponse,
HttpHeaders,
} from '@angular/common/http';
import { throwError, Subject } from 'rxjs';
import { takeUntil, timeoutWith } from 'rxjs/operators';
import { Deferred, DeferredObj } from 'devextreme/core/utils/deferred';
import { isDefined } from 'devextreme/core/utils/type';
import { getWindow } from 'devextreme/core/utils/window';
Expand Down Expand Up @@ -33,6 +37,10 @@ interface XHRSurrogate {
statusText?: string;
}

interface SubscriptionLike {
unsubscribe: () => void;
}

const PARSER_ERROR = 'parsererror';
const SUCCESS = 'success';
const ERROR = 'error';
Expand Down Expand Up @@ -206,7 +214,9 @@ function getUploadCallbacks(options: Options, deferred: DeferredResult, xhrSurro
}

export const sendRequestFactory = (httpClient: HttpClient) => (options: Options) => {
const abort$ = new Subject<void>();
let subscription: SubscriptionLike | null = null;
let timeoutId: ReturnType<typeof setTimeout> | null = null;

const deferred: DeferredResult = Deferred();
const result = deferred.promise() as Result;
const isGet = isGetMethod(options);
Expand All @@ -216,13 +226,23 @@ export const sendRequestFactory = (httpClient: HttpClient) => (options: Options)
options.crossDomain = isCrossDomain(options.url);
options.cache = isCacheNeed(options);

const clearTimeoutIfSet = () => {
if (timeoutId !== null) {
clearTimeout(timeoutId);
timeoutId = null;
}
};

const headers = getRequestHeaders(options);
const xhrSurrogate: XHRSurrogate = {
type: 'XMLHttpRequestSurrogate',
aborted: false,
abort() {
this.aborted = true;
abort$.next();
clearTimeoutIfSet();
subscription?.unsubscribe();
subscription = null;
rejectIfAborted(deferred, this, () => options.upload?.onabort?.(this));
},
};

Expand Down Expand Up @@ -276,18 +296,36 @@ export const sendRequestFactory = (httpClient: HttpClient) => (options: Options)
},
);

const subscriptionCallbacks = upload
? getUploadCallbacks
: getRequestCallbacks;

request.pipe.apply(request, [
takeUntil(abort$) as any,
...options.timeout
? [timeoutWith(options.timeout, throwError({ statusText: TIMEOUT, status: 0, ok: false })) as any]
: [],
]).subscribe(
subscriptionCallbacks(options, deferred, xhrSurrogate),
);
const callbacks = upload
? getUploadCallbacks(options, deferred, xhrSurrogate)
: getRequestCallbacks(options, deferred, xhrSurrogate);

if (options.timeout) {
timeoutId = setTimeout(() => {
timeoutId = null;
subscription?.unsubscribe();
subscription = null;
const timeoutError = {
statusText: TIMEOUT,
status: 0,
ok: false,
headers: new HttpHeaders(),
} as HttpErrorResponse;
callbacks.error(timeoutError);
}, options.timeout);
}

subscription = request.subscribe({
next(value) {
clearTimeoutIfSet();
callbacks.next(value);
},
error(err) {
clearTimeoutIfSet();
callbacks.error(err);
},
complete: callbacks.complete,
});

return result;
};