chore(facade): remove most facade/async functions
This commit is contained in:

committed by
Alex Rickabaugh

parent
6baf3baedd
commit
99989f5d3f
@ -9,7 +9,6 @@
|
||||
import {XHR} from '@angular/compiler';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {global} from '../facade/lang';
|
||||
import {PromiseWrapper} from '../facade/promise';
|
||||
|
||||
/**
|
||||
* An implementation of XHR that uses a template cache to avoid doing an actual
|
||||
@ -31,9 +30,9 @@ export class CachedXHR extends XHR {
|
||||
|
||||
get(url: string): Promise<string> {
|
||||
if (this._cache.hasOwnProperty(url)) {
|
||||
return PromiseWrapper.resolve(this._cache[url]);
|
||||
return Promise.resolve(this._cache[url]);
|
||||
} else {
|
||||
return PromiseWrapper.reject('CachedXHR: Did not find cached template for ' + url, null);
|
||||
return <Promise<any>>Promise.reject('CachedXHR: Did not find cached template for ' + url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,16 @@ import {XHR} from '@angular/compiler';
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {PromiseCompleter, PromiseWrapper} from '../facade/promise';
|
||||
|
||||
@Injectable()
|
||||
export class XHRImpl extends XHR {
|
||||
get(url: string): Promise<string> {
|
||||
var completer: PromiseCompleter<string> = PromiseWrapper.completer();
|
||||
var resolve: (result: any) => void;
|
||||
var reject: (error: any) => void;
|
||||
const promise = new Promise((res, rej) => {
|
||||
resolve = res;
|
||||
reject = rej;
|
||||
});
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'text';
|
||||
@ -35,15 +39,15 @@ export class XHRImpl extends XHR {
|
||||
}
|
||||
|
||||
if (200 <= status && status <= 300) {
|
||||
completer.resolve(response);
|
||||
resolve(response);
|
||||
} else {
|
||||
completer.reject(`Failed to load ${url}`, null);
|
||||
reject(`Failed to load ${url}`);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() { completer.reject(`Failed to load ${url}`, null); };
|
||||
xhr.onerror = function() { reject(`Failed to load ${url}`); };
|
||||
|
||||
xhr.send();
|
||||
return completer.promise;
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user