Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit e5859a5

Browse files
committed
Revert "feat(http): support coalescing http requests"
This reverts commit 1fb668b. Only reverting because g3 is not ready for it yet.
1 parent 1fb668b commit e5859a5

File tree

5 files changed

+34
-123
lines changed

5 files changed

+34
-123
lines changed

lib/core/module.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export "package:angular/core_dom/module_internal.dart" show
3939
EventHandler,
4040
Http,
4141
HttpBackend,
42-
HttpConfig,
4342
HttpDefaultHeaders,
4443
HttpDefaults,
4544
HttpInterceptor,

lib/core_dom/http.dart

Lines changed: 34 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ typedef RequestInterceptor(HttpResponseConfig);
3838
typedef RequestErrorInterceptor(dynamic);
3939
typedef Response(HttpResponse);
4040
typedef ResponseError(dynamic);
41-
typedef _CompleteResponse(HttpResponse);
42-
typedef _RunCoaleced(fn());
43-
44-
_runNow(fn()) => fn();
45-
_identity(x) => x;
4641

4742
/**
4843
* HttpInterceptors are used to modify the Http request. They can be added to
@@ -374,29 +369,23 @@ class HttpDefaults {
374369
*/
375370
@Injectable()
376371
class Http {
377-
final _pendingRequests = new HashMap<String, async.Future<HttpResponse>>();
378-
final BrowserCookies _cookies;
379-
final LocationWrapper _location;
380-
final UrlRewriter _rewriter;
381-
final HttpBackend _backend;
382-
final HttpInterceptors _interceptors;
383-
final RootScope _rootScope;
384-
final HttpConfig _httpConfig;
385-
final VmTurnZone _zone;
386-
387-
final _responseQueue = <Function>[];
388-
async.Timer _responseQueueTimer;
372+
var _pendingRequests = new HashMap<String, async.Future<HttpResponse>>();
373+
BrowserCookies _cookies;
374+
LocationWrapper _location;
375+
UrlRewriter _rewriter;
376+
HttpBackend _backend;
377+
HttpInterceptors _interceptors;
389378

390379
/**
391380
* The defaults for [Http]
392381
*/
393-
final HttpDefaults defaults;
382+
HttpDefaults defaults;
394383

395384
/**
396385
* Constructor, useful for DI.
397386
*/
398-
Http(this._cookies, this._location, this._rewriter, this._backend, this.defaults,
399-
this._interceptors, this._rootScope, this._httpConfig, this._zone);
387+
Http(this._cookies, this._location, this._rewriter, this._backend,
388+
this.defaults, this._interceptors);
400389

401390
/**
402391
* Parse a [requestUrl] and determine whether this is a same-origin request as
@@ -493,25 +482,29 @@ class Http {
493482
return new async.Future.value(new HttpResponse.copy(cachedResponse));
494483
}
495484

496-
requestFromBackend(runCoalesced, onComplete, onError) => _backend.request(
497-
url,
498-
method: method,
499-
requestHeaders: config.headers,
500-
sendData: config.data,
501-
withCredentials: withCredentials
502-
).then((dom.HttpRequest req) => _onResponse(req, runCoalesced, onComplete, config, cache, url),
503-
onError: (e) => _onError(e, runCoalesced, onError, config, url));
504-
505-
async.Future responseFuture;
506-
if (_httpConfig.coalesceDuration != null) {
507-
async.Completer completer = new async.Completer();
508-
responseFuture = completer.future;
509-
_zone.runOutsideAngular(() => requestFromBackend(
510-
_coalesce, completer.complete, completer.completeError));
511-
} else {
512-
responseFuture = requestFromBackend(_runNow, _identity, _identity);
513-
}
514-
return _pendingRequests[url] = responseFuture;
485+
var result = _backend.request(url,
486+
method: method,
487+
requestHeaders: config.headers,
488+
sendData: config.data,
489+
withCredentials: withCredentials).then((dom.HttpRequest value) {
490+
// TODO: Uncomment after apps migrate off of this class.
491+
// assert(value.status >= 200 && value.status < 300);
492+
493+
var response = new HttpResponse(value.status, value.responseText,
494+
parseHeaders(value), config);
495+
496+
if (cache != null) cache.put(url, response);
497+
_pendingRequests.remove(url);
498+
return response;
499+
}, onError: (error) {
500+
if (error is! dom.ProgressEvent) throw error;
501+
dom.ProgressEvent event = error;
502+
_pendingRequests.remove(url);
503+
dom.HttpRequest request = event.currentTarget;
504+
return new async.Future.error(
505+
new HttpResponse(request.status, request.response, parseHeaders(request), config));
506+
});
507+
return _pendingRequests[url] = result;
515508
};
516509

517510
var chain = [[serverRequest, null]];
@@ -657,50 +650,11 @@ class Http {
657650
xsrfCookieName: xsrfCookieName, interceptors: interceptors, cache: cache,
658651
timeout: timeout);
659652

660-
_onResponse(dom.HttpRequest request, _RunCoaleced runCoalesced, _CompleteResponse onComplete,
661-
HttpResponseConfig config, cache, String url) {
662-
// TODO: Uncomment after apps migrate off of this class.
663-
// assert(request.status >= 200 && request.status < 300);
664-
665-
var response = new HttpResponse(
666-
request.status, request.responseText, parseHeaders(request), config);
667-
668-
if (cache != null) cache.put(url, response);
669-
_pendingRequests.remove(url);
670-
return runCoalesced(() => onComplete(response));
671-
}
672-
673-
_onError(error, _RunCoaleced runCoalesced, _CompleteResponse onError,
674-
HttpResponseConfig config, String url) {
675-
if (error is! dom.ProgressEvent) throw error;
676-
dom.ProgressEvent event = error;
677-
_pendingRequests.remove(url);
678-
dom.HttpRequest request = event.currentTarget;
679-
var response = new HttpResponse(
680-
request.status, request.response, parseHeaders(request), config);
681-
return runCoalesced(() => onError(new async.Future.error(response)));
682-
}
683-
684-
_coalesce(fn()) {
685-
_responseQueue.add(fn);
686-
if (_responseQueueTimer == null) {
687-
_responseQueueTimer = new async.Timer(_httpConfig.coalesceDuration, _flushResponseQueue);
688-
}
689-
}
690-
691-
_flushResponseQueue() => _rootScope.apply(_flushResponseQueueSync);
692-
693-
_flushResponseQueueSync() {
694-
_responseQueueTimer = null;
695-
_responseQueue.forEach(_runNow);
696-
_responseQueue.clear();
697-
}
698-
699653
/**
700654
* Parse raw headers into key-value object
701655
*/
702-
static Map<String, String> parseHeaders(dom.HttpRequest request) {
703-
var headers = request.getAllResponseHeaders();
656+
static Map<String, String> parseHeaders(dom.HttpRequest value) {
657+
var headers = value.getAllResponseHeaders();
704658

705659
var parsed = new HashMap();
706660

@@ -750,10 +704,3 @@ class Http {
750704
.replaceAll('%2C', ',')
751705
.replaceAll('%20', pctEncodeSpaces ? '%20' : '+');
752706
}
753-
754-
@Injectable()
755-
class HttpConfig {
756-
final Duration coalesceDuration;
757-
758-
HttpConfig({this.coalesceDuration});
759-
}

lib/core_dom/module_internal.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class CoreDomModule extends Module {
8484
bind(HttpDefaultHeaders);
8585
bind(HttpDefaults);
8686
bind(HttpInterceptors);
87-
bind(HttpConfig, toValue: new HttpConfig());
8887
bind(Animate);
8988
bind(ViewCache);
9089
bind(BrowserCookies);

test/angular_spec.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ main() {
124124
"angular.core.dom_internal.EventHandler",
125125
"angular.core.dom_internal.Http",
126126
"angular.core.dom_internal.HttpBackend",
127-
"angular.core.dom_internal.HttpConfig",
128127
"angular.core.dom_internal.HttpDefaultHeaders",
129128
"angular.core.dom_internal.HttpDefaults",
130129
"angular.core.dom_internal.HttpInterceptor",

test/core_dom/http_spec.dart

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,39 +1422,6 @@ void main() {
14221422
});
14231423
});
14241424
});
1425-
1426-
describe('coalesce', () {
1427-
beforeEachModule((Module module) {
1428-
var coalesceDuration = new Duration(milliseconds: 100);
1429-
module.bind(HttpConfig, toValue: new HttpConfig(coalesceDuration: coalesceDuration));
1430-
});
1431-
1432-
it('should coalesce requests', async((Http http) {
1433-
backend.expect('GET', '/foo').respond(200, 'foo');
1434-
backend.expect('GET', '/bar').respond(200, 'bar');
1435-
1436-
var fooResp, barResp;
1437-
http.get('/foo').then((HttpResponse resp) => fooResp = resp.data);
1438-
http.get('/bar').then((HttpResponse resp) => barResp = resp.data);
1439-
1440-
microLeap();
1441-
backend.flush();
1442-
microLeap();
1443-
expect(fooResp).toBeNull();
1444-
expect(barResp).toBeNull();
1445-
1446-
clockTick(milliseconds: 99);
1447-
microLeap();
1448-
expect(fooResp).toBeNull();
1449-
expect(barResp).toBeNull();
1450-
1451-
clockTick(milliseconds: 1);
1452-
microLeap();
1453-
expect(fooResp).toEqual('foo');
1454-
expect(barResp).toEqual('bar');
1455-
}));
1456-
1457-
});
14581425
});
14591426
}
14601427

0 commit comments

Comments
 (0)