refactor(xhr): move render's xhr implementation to render/

The existence of this module in the services/ folder led some to believe xhr
is meant to be a general-purpose http library.

Fixes #2305
This commit is contained in:
Jeff Cross
2015-06-09 10:21:25 -07:00
parent 21568106b1
commit f34f8df319
18 changed files with 17 additions and 17 deletions
-5
View File
@@ -1,5 +0,0 @@
import {Promise} from 'angular2/src/facade/async';
export class XHR {
get(url: string): Promise<string> { return null; }
}
@@ -1,14 +0,0 @@
library angular2.src.services.xhr_impl;
import 'dart:async' show Future;
import 'dart:html' show HttpRequest;
import 'package:angular2/di.dart';
import './xhr.dart' show XHR;
@Injectable()
class XHRImpl extends XHR {
Future<String> get(String url) {
return HttpRequest.request(url).then((HttpRequest req) => req.responseText,
onError: (_) => new Future.error('Failed to load $url'));
}
}
-27
View File
@@ -1,27 +0,0 @@
import {Injectable} from 'angular2/di';
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
import {XHR} from './xhr';
@Injectable()
export class XHRImpl extends XHR {
get(url: string): Promise<string> {
var completer = PromiseWrapper.completer();
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'text';
xhr.onload = function() {
var status = xhr.status;
if (200 <= status && status <= 300) {
completer.resolve(xhr.responseText);
} else {
completer.reject(`Failed to load ${url}`, null);
}
};
xhr.onerror = function() { completer.reject(`Failed to load ${url}`, null); };
xhr.send();
return completer.promise;
}
}