refactor: move angular source to /packages rather than modules/@angular
This commit is contained in:
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* 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 {ResourceLoader, platformCoreDynamic} from '@angular/compiler';
|
||||
import {PlatformRef, Provider, createPlatformFactory} from '@angular/core';
|
||||
|
||||
import {INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS} from './platform_providers';
|
||||
import {CachedResourceLoader} from './resource_loader/resource_loader_cache';
|
||||
|
||||
export * from './private_export';
|
||||
export {VERSION} from './version';
|
||||
/**
|
||||
* @experimental
|
||||
*/
|
||||
export const RESOURCE_CACHE_PROVIDER: Provider[] =
|
||||
[{provide: ResourceLoader, useClass: CachedResourceLoader}];
|
||||
|
||||
/**
|
||||
* @stable
|
||||
*/
|
||||
export const platformBrowserDynamic = createPlatformFactory(
|
||||
platformCoreDynamic, 'browserDynamic', INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
|
25
packages/platform-browser-dynamic/src/platform_providers.ts
Normal file
25
packages/platform-browser-dynamic/src/platform_providers.ts
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* 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 {ɵPLATFORM_BROWSER_ID as PLATFORM_BROWSER_ID} from '@angular/common';
|
||||
import {ResourceLoader} from '@angular/compiler';
|
||||
import {COMPILER_OPTIONS, PLATFORM_ID, Provider} from '@angular/core';
|
||||
|
||||
import {ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS as INTERNAL_BROWSER_PLATFORM_PROVIDERS} from '@angular/platform-browser';
|
||||
|
||||
import {ResourceLoaderImpl} from './resource_loader/resource_loader_impl';
|
||||
|
||||
export const INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS: Provider[] = [
|
||||
INTERNAL_BROWSER_PLATFORM_PROVIDERS,
|
||||
{
|
||||
provide: COMPILER_OPTIONS,
|
||||
useValue: {providers: [{provide: ResourceLoader, useClass: ResourceLoaderImpl}]},
|
||||
multi: true
|
||||
},
|
||||
{provide: PLATFORM_ID, useValue: PLATFORM_BROWSER_ID},
|
||||
];
|
10
packages/platform-browser-dynamic/src/private_export.ts
Normal file
10
packages/platform-browser-dynamic/src/private_export.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
export {INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS as ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS} from './platform_providers';
|
||||
export {ResourceLoaderImpl as ɵResourceLoaderImpl} from './resource_loader/resource_loader_impl';
|
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* 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 {ResourceLoader} from '@angular/compiler';
|
||||
import {ɵglobal as global} from '@angular/core';
|
||||
|
||||
/**
|
||||
* 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 CachedResourceLoader extends ResourceLoader {
|
||||
private _cache: {[url: string]: string};
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._cache = (<any>global).$templateCache;
|
||||
if (this._cache == null) {
|
||||
throw new Error('CachedResourceLoader: Template cache was not found in $templateCache.');
|
||||
}
|
||||
}
|
||||
|
||||
get(url: string): Promise<string> {
|
||||
if (this._cache.hasOwnProperty(url)) {
|
||||
return Promise.resolve(this._cache[url]);
|
||||
} else {
|
||||
return <Promise<any>>Promise.reject(
|
||||
'CachedResourceLoader: Did not find cached template for ' + url);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* 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 {ResourceLoader} from '@angular/compiler';
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ResourceLoaderImpl extends ResourceLoader {
|
||||
get(url: string): Promise<string> {
|
||||
let resolve: (result: any) => void;
|
||||
let reject: (error: any) => void;
|
||||
const promise = new Promise((res, rej) => {
|
||||
resolve = res;
|
||||
reject = rej;
|
||||
});
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'text';
|
||||
|
||||
xhr.onload = function() {
|
||||
// responseText is the old-school way of retrieving response (supported by IE8 & 9)
|
||||
// response/responseType properties were introduced in ResourceLoader Level2 spec (supported
|
||||
// by IE10)
|
||||
const response = xhr.response || xhr.responseText;
|
||||
|
||||
// normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
|
||||
let status = xhr.status === 1223 ? 204 : xhr.status;
|
||||
|
||||
// fix status code when it is 0 (0 status is undocumented).
|
||||
// Occurs when accessing file resources or on Android 4.1 stock browser
|
||||
// while retrieving files from application cache.
|
||||
if (status === 0) {
|
||||
status = response ? 200 : 0;
|
||||
}
|
||||
|
||||
if (200 <= status && status <= 300) {
|
||||
resolve(response);
|
||||
} else {
|
||||
reject(`Failed to load ${url}`);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() { reject(`Failed to load ${url}`); };
|
||||
|
||||
xhr.send();
|
||||
return promise;
|
||||
}
|
||||
}
|
19
packages/platform-browser-dynamic/src/version.ts
Normal file
19
packages/platform-browser-dynamic/src/version.ts
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @module
|
||||
* @description
|
||||
* Entry point for all public APIs of the common package.
|
||||
*/
|
||||
|
||||
import {Version} from '@angular/core';
|
||||
/**
|
||||
* @stable
|
||||
*/
|
||||
export const VERSION = new Version('0.0.0-PLACEHOLDER');
|
Reference in New Issue
Block a user