Skip to content

Commit e2a459a

Browse files
committed
Remove applyAsync from http
1 parent 900ef3d commit e2a459a

3 files changed

Lines changed: 37 additions & 208 deletions

File tree

src/core/compile/compile.spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5983,8 +5983,16 @@ describe("$compile", () => {
59835983
});
59845984

59855985
it("should allow all template URLs by default", async () => {
5986-
$compile("<div cross-domain-template></div>")($rootScope);
5986+
$templateCache.set(
5987+
"http://example.com/should-not-load.html",
5988+
"<span>example.com/cached-version</span>",
5989+
);
5990+
element = $compile("<div cross-domain-template></div>")($rootScope);
59875991
await wait();
5992+
5993+
expect(element.outerHTML).toEqual(
5994+
'<div cross-domain-template=""><span>example.com/cached-version</span></div>',
5995+
);
59885996
expect(errors.length).toBe(0);
59895997
});
59905998

src/services/http/http.spec.js

Lines changed: 6 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,63 +1127,15 @@ describe("$http", function () {
11271127
});
11281128
});
11291129

1130-
describe("useApplyAsync", function () {
1131-
beforeEach(function () {
1132-
const injector = createInjector([
1133-
"ng",
1134-
function ($httpProvider) {
1135-
$httpProvider.useApplyAsync(true);
1136-
},
1137-
]);
1138-
$http = injector.get("$http");
1139-
$rootScope = injector.get("$rootScope");
1140-
});
1141-
1142-
it("does not resolve promise immediately when enabled", async function () {
1143-
const resolvedSpy = jasmine.createSpy();
1144-
$http.get("/mock/hello").then(resolvedSpy);
1145-
await wait();
1146-
1147-
expect(resolvedSpy).not.toHaveBeenCalled();
1148-
});
1149-
1150-
it("resolves promise later when enabled", async function () {
1151-
const resolvedSpy = jasmine.createSpy();
1152-
await $http.get("/mock/hello").then(resolvedSpy);
1153-
await wait();
1130+
it("calls configured event handlers", async function () {
1131+
const loadSpy = jasmine.createSpy("load");
11541132

1155-
expect(resolvedSpy).toHaveBeenCalled();
1133+
await $http.get("/mock/hello", {
1134+
eventHandlers: { load: loadSpy },
11561135
});
11571136

1158-
it("defers configured event handlers when enabled", async function () {
1159-
const loadSpy = jasmine.createSpy("load");
1160-
1161-
await $http.get("/mock/hello", {
1162-
eventHandlers: { load: loadSpy },
1163-
});
1164-
1165-
await wait();
1166-
expect(loadSpy).toHaveBeenCalled();
1167-
});
1168-
});
1169-
1170-
describe("provider configuration", function () {
1171-
it("returns the current deferred response setting", function () {
1172-
let initial;
1173-
let updated;
1174-
1175-
createInjector([
1176-
"ng",
1177-
function ($httpProvider) {
1178-
initial = $httpProvider.useApplyAsync();
1179-
$httpProvider.useApplyAsync(true);
1180-
updated = $httpProvider.useApplyAsync();
1181-
},
1182-
]);
1183-
1184-
expect(initial).toBe(false);
1185-
expect(updated).toBe(true);
1186-
});
1137+
await wait();
1138+
expect(loadSpy).toHaveBeenCalled();
11871139
});
11881140
});
11891141

@@ -3921,98 +3873,6 @@ describe("http", () => {
39213873
// });
39223874
// });
39233875

3924-
// describe("$http with deferred delivery", () => {
3925-
// let $http;
3926-
// let $httpBackend;
3927-
// let $rootScope;
3928-
// let $browser;
3929-
// let log;
3930-
3931-
// beforeEach(inject([
3932-
// "$http",
3933-
// "$httpBackend",
3934-
// "$rootScope",
3935-
// "$browser",
3936-
// "log",
3937-
// function (http, backend, scope, browser, logger) {
3938-
// $http = http;
3939-
// $httpBackend = backend;
3940-
// $rootScope = scope;
3941-
// $browser = browser;
3942-
// spyOn($rootScope, "digest entry").and.callThrough();
3943-
// spyOn($rootScope, "deferred delivery").and.callThrough();
3944-
// spyOn($rootScope, "$digest").and.callThrough();
3945-
// spyOn($browser.defer, "cancel").and.callThrough();
3946-
// log = logger;
3947-
// },
3948-
// ]));
3949-
3950-
// it("should schedule coalesced apply on response", () => {
3951-
// const handler = jasmine.createSpy("handler");
3952-
// $httpBackend
3953-
// .expect("GET", "/template1.html")
3954-
// .respond(200, "<h1>Header!</h1>", {});
3955-
// $http.get("/template1.html").then(handler);
3956-
// // Ensure requests are sent
3957-
// ;
3958-
3959-
// $httpBackend.flush(null, null, false);
3960-
// expect($rootScope.deferred delivery).toHaveBeenCalled();
3961-
// expect(handler).not.toHaveBeenCalled();
3962-
3963-
// $browser.defer.flush();
3964-
// expect(handler).toHaveBeenCalled();
3965-
// });
3966-
3967-
// it("should combine multiple responses within short time frame into a single digest entry", () => {
3968-
// $httpBackend
3969-
// .expect("GET", "/template1.html")
3970-
// .respond(200, "<h1>Header!</h1>", {});
3971-
// $httpBackend
3972-
// .expect("GET", "/template2.html")
3973-
// .respond(200, "<p>Body!</p>", {});
3974-
3975-
// $http.get("/template1.html").then(log.fn("response 1"));
3976-
// $http.get("/template2.html").then(log.fn("response 2"));
3977-
// // Ensure requests are sent
3978-
// ;
3979-
3980-
// $httpBackend.flush(null, null, false);
3981-
// expect(log).toEqual([]);
3982-
3983-
// $browser.defer.flush();
3984-
// expect(log).toEqual(["response 1", "response 2"]);
3985-
// });
3986-
3987-
// it("should handle pending responses immediately if a digest occurs on $rootScope", () => {
3988-
// $httpBackend
3989-
// .expect("GET", "/template1.html")
3990-
// .respond(200, "<h1>Header!</h1>", {});
3991-
// $httpBackend
3992-
// .expect("GET", "/template2.html")
3993-
// .respond(200, "<p>Body!</p>", {});
3994-
// $httpBackend
3995-
// .expect("GET", "/template3.html")
3996-
// .respond(200, "<p>Body!</p>", {});
3997-
3998-
// $http.get("/template1.html").then(log.fn("response 1"));
3999-
// $http.get("/template2.html").then(log.fn("response 2"));
4000-
// $http.get("/template3.html").then(log.fn("response 3"));
4001-
// // Ensure requests are sent
4002-
// ;
4003-
4004-
// // Intermediate $digest occurs before 3rd response is received, assert that pending responses
4005-
// /// are handled
4006-
// $httpBackend.flush(2);
4007-
// expect(log).toEqual(["response 1", "response 2"]);
4008-
4009-
// // Finally, third response is received, and a second coalesced digest entry is started
4010-
// $httpBackend.flush(null, null, false);
4011-
// $browser.defer.flush();
4012-
// expect(log).toEqual(["response 1", "response 2", "response 3"]);
4013-
// });
4014-
// });
4015-
40163876
// describe("$http param serializers", () => {
40173877
// let defSer;
40183878
// let jqrSer;

src/services/http/http.ts

Lines changed: 22 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -535,29 +535,6 @@ export function HttpProvider(this: any): void {
535535
paramSerializer: _httpParamSerializer,
536536
});
537537

538-
let useApplyAsync = false;
539-
540-
/**
541-
* Configure $http service to defer processing of responses received at around the
542-
* same time. This can reduce repeated response work for applications that make
543-
* many HTTP requests concurrently (common during application bootstrap).
544-
*
545-
* Defaults to false. If no value is specified, returns the current configured value.
546-
*
547-
* @param value - If true, completed requests are deferred to the next tick.
548-
*
549-
* @returns The `$httpProvider` for chaining when setting a value, otherwise the current flag.
550-
*/
551-
this.useApplyAsync = function (value?: boolean) {
552-
if (isDefined(value)) {
553-
useApplyAsync = !!value;
554-
555-
return this;
556-
}
557-
558-
return useApplyAsync;
559-
};
560-
561538
/**
562539
* Array containing service factories for all synchronous or asynchronous `$http`
563540
* pre-processing of request or postprocessing of responses.
@@ -1015,45 +992,37 @@ export function HttpProvider(this: any): void {
1015992
config.timeout,
1016993
config.withCredentials,
1017994
config.responseType as XMLHttpRequestResponseType | undefined,
1018-
createApplyHandlers(config.eventHandlers),
1019-
createApplyHandlers(config.uploadEventHandlers),
995+
createEventHandlers(config.eventHandlers),
996+
createEventHandlers(config.uploadEventHandlers),
1020997
);
1021998
}
1022999

10231000
return promise;
10241001

1025-
/** Wraps raw XHR event handlers so optional deferred delivery is consistent. */
1026-
function createApplyHandlers(
1002+
/** Wraps raw XHR event handlers with function/object listener support. */
1003+
function createEventHandlers(
10271004
eventHandlers:
10281005
| RequestConfig["eventHandlers"]
10291006
| RequestConfig["uploadEventHandlers"],
10301007
): Record<string, EventListener> {
10311008
if (eventHandlers) {
1032-
const applyHandlers: Record<string, EventListener> = {};
1009+
const handlers: Record<string, EventListener> = {};
10331010

10341011
entries(eventHandlers).forEach(([key, eventHandler]) => {
1035-
applyHandlers[key] = function (event: Event) {
1036-
if (useApplyAsync) {
1037-
setTimeout(() => callEventHandler());
1038-
} else {
1039-
callEventHandler();
1040-
}
1041-
1042-
function callEventHandler() {
1043-
if (isFunction(eventHandler)) {
1044-
eventHandler(event);
1045-
} else if (
1046-
eventHandler &&
1047-
typeof eventHandler === "object" &&
1048-
"handleEvent" in eventHandler
1049-
) {
1050-
(eventHandler as EventListenerObject).handleEvent(event);
1051-
}
1012+
handlers[key] = function (event: Event) {
1013+
if (isFunction(eventHandler)) {
1014+
eventHandler(event);
1015+
} else if (
1016+
eventHandler &&
1017+
typeof eventHandler === "object" &&
1018+
"handleEvent" in eventHandler
1019+
) {
1020+
(eventHandler as EventListenerObject).handleEvent(event);
10521021
}
10531022
};
10541023
});
10551024

1056-
return applyHandlers;
1025+
return handlers;
10571026
} else {
10581027
return {};
10591028
}
@@ -1082,21 +1051,13 @@ export function HttpProvider(this: any): void {
10821051
}
10831052
}
10841053

1085-
function resolveHttpPromise() {
1086-
resolvePromise(
1087-
response,
1088-
status,
1089-
headersString,
1090-
statusText,
1091-
xhrStatus,
1092-
);
1093-
}
1094-
1095-
if (useApplyAsync) {
1096-
setTimeout(resolveHttpPromise);
1097-
} else {
1098-
resolveHttpPromise();
1099-
}
1054+
resolvePromise(
1055+
response,
1056+
status,
1057+
headersString,
1058+
statusText,
1059+
xhrStatus,
1060+
);
11001061
}
11011062

11021063
/** Resolves or rejects the raw `$http` promise from a low-level XHR callback payload. */

0 commit comments

Comments
 (0)