fix(platform-browser-dynamic): Rename CACHED_TEMPLATE_PROVIDER to RESOURCE_CACHE_PROVIDER (#10866)

* fix(platform-browser-dynamic): Rename CACHED_TEMPLATE_PROVIDER to RESOURCE_CACHE_PROVIDER

Closes #9741

BREAKING CHANGE:

`CACHED_TEMPLATE_PROVIDER` is now renamed to `RESOURCE_CACHE_PROVIDER`

Before:

```js
import {CACHED_TEMPLATE_PROVIDER} from '@angular/platform-browser-dynamic';
```

After:

```js
import {RESOURCE_CACHE_PROVIDER} from '@angular/platform-browser-dynamic';
```

* Rename XHR -> ResourceLoader
This commit is contained in:
Hans
2016-08-17 09:24:44 -07:00
committed by vikerman
parent 951ecb4d90
commit 40e160c22c
29 changed files with 213 additions and 190 deletions

View File

@ -6,18 +6,18 @@
* found in the LICENSE file at https://angular.io/license
*/
import {XHR} from '@angular/compiler';
import {ResourceLoader} from '@angular/compiler';
import {COMPILER_OPTIONS} from '@angular/core';
import {INTERNAL_BROWSER_PLATFORM_PROVIDERS} from '../platform_browser_private';
import {XHRImpl} from './xhr/xhr_impl';
import {ResourceLoaderImpl} from './resource_loader/resource_loader_impl';
export const INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS: any[] = [
INTERNAL_BROWSER_PLATFORM_PROVIDERS,
{
provide: COMPILER_OPTIONS,
useValue: {providers: [{provide: XHR, useClass: XHRImpl}]},
useValue: {providers: [{provide: ResourceLoader, useClass: ResourceLoaderImpl}]},
multi: true
},
];

View File

@ -6,25 +6,26 @@
* found in the LICENSE file at https://angular.io/license
*/
import {XHR} from '@angular/compiler';
import {ResourceLoader} from '@angular/compiler';
import {BaseException} from '@angular/core';
import {global} from '../facade/lang';
/**
* An implementation of XHR that uses a template cache to avoid doing an actual
* XHR.
* An implementation of ResourceLoader that uses a template cache to avoid doing an actual
* ResourceLoader.
*
* The template cache needs to be built and loaded into window.$templateCache
* via a separate mechanism.
*/
export class CachedXHR extends XHR {
export class CachedResourceLoader extends ResourceLoader {
private _cache: {[url: string]: string};
constructor() {
super();
this._cache = (<any>global).$templateCache;
if (this._cache == null) {
throw new BaseException('CachedXHR: Template cache was not found in $templateCache.');
throw new BaseException(
'CachedResourceLoader: Template cache was not found in $templateCache.');
}
}
@ -32,7 +33,8 @@ export class CachedXHR extends XHR {
if (this._cache.hasOwnProperty(url)) {
return Promise.resolve(this._cache[url]);
} else {
return <Promise<any>>Promise.reject('CachedXHR: Did not find cached template for ' + url);
return <Promise<any>>Promise.reject(
'CachedResourceLoader: Did not find cached template for ' + url);
}
}
}

View File

@ -5,13 +5,13 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {XHR} from '@angular/compiler';
import {ResourceLoader} from '@angular/compiler';
import {Injectable} from '@angular/core';
import {isPresent} from '../facade/lang';
@Injectable()
export class XHRImpl extends XHR {
export class ResourceLoaderImpl extends ResourceLoader {
get(url: string): Promise<string> {
var resolve: (result: any) => void;
var reject: (error: any) => void;
@ -25,7 +25,8 @@ export class XHRImpl extends XHR {
xhr.onload = function() {
// responseText is the old-school way of retrieving response (supported by IE8 & 9)
// response/responseType properties were introduced in XHR Level2 spec (supported by IE10)
// response/responseType properties were introduced in ResourceLoader Level2 spec (supported
// by IE10)
var response = isPresent(xhr.response) ? xhr.response : xhr.responseText;
// normalize IE9 bug (http://bugs.jquery.com/ticket/1450)