refactor: misc cleanup
This commit is contained in:
parent
0ca971c5bd
commit
f23b22a0f4
|
@ -115,27 +115,27 @@ export class DirectiveNormalizer {
|
|||
const templateStyles = this.normalizeStylesheet(new CompileStylesheetMetadata(
|
||||
{styles: visitor.styles, styleUrls: visitor.styleUrls, moduleUrl: templateAbsUrl}));
|
||||
|
||||
const allStyles = templateMetadataStyles.styles.concat(templateStyles.styles);
|
||||
const allStyleUrls = templateMetadataStyles.styleUrls.concat(templateStyles.styleUrls);
|
||||
|
||||
let encapsulation = templateMeta.encapsulation;
|
||||
if (isBlank(encapsulation)) {
|
||||
encapsulation = this._config.defaultEncapsulation;
|
||||
}
|
||||
if (encapsulation === ViewEncapsulation.Emulated && allStyles.length === 0 &&
|
||||
allStyleUrls.length === 0) {
|
||||
|
||||
const styles = templateMetadataStyles.styles.concat(templateStyles.styles);
|
||||
const styleUrls = templateMetadataStyles.styleUrls.concat(templateStyles.styleUrls);
|
||||
|
||||
if (encapsulation === ViewEncapsulation.Emulated && styles.length === 0 &&
|
||||
styleUrls.length === 0) {
|
||||
encapsulation = ViewEncapsulation.None;
|
||||
}
|
||||
|
||||
return new CompileTemplateMetadata({
|
||||
encapsulation,
|
||||
template: template,
|
||||
templateUrl: templateAbsUrl,
|
||||
styles: allStyles,
|
||||
styleUrls: allStyleUrls,
|
||||
template,
|
||||
templateUrl: templateAbsUrl, styles, styleUrls,
|
||||
externalStylesheets: templateMeta.externalStylesheets,
|
||||
ngContentSelectors: visitor.ngContentSelectors,
|
||||
animations: templateMeta.animations,
|
||||
interpolation: templateMeta.interpolation
|
||||
interpolation: templateMeta.interpolation,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,6 @@ function _cloneDirectiveWithTemplate(
|
|||
viewProviders: directive.viewProviders,
|
||||
queries: directive.queries,
|
||||
viewQueries: directive.viewQueries,
|
||||
entryComponents: directive.entryComponents,
|
||||
template: template
|
||||
entryComponents: directive.entryComponents, template,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import {LOCALE_ID} from './i18n/tokens';
|
|||
import {Compiler} from './linker/compiler';
|
||||
import {ViewUtils} from './linker/view_utils';
|
||||
import {NgModule} from './metadata';
|
||||
import {Type} from './type';
|
||||
|
||||
export function _iterableDiffersFactory() {
|
||||
return defaultIterableDiffers;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import {ErrorHandler} from '../src/error_handler';
|
||||
import {ListWrapper} from '../src/facade/collection';
|
||||
import {unimplemented} from '../src/facade/errors';
|
||||
import {isBlank, isPresent, stringify} from '../src/facade/lang';
|
||||
import {stringify} from '../src/facade/lang';
|
||||
import {isPromise} from '../src/util/lang';
|
||||
|
||||
import {ApplicationInitStatus} from './application_init';
|
||||
|
@ -26,9 +26,9 @@ import {Testability, TestabilityRegistry} from './testability/testability';
|
|||
import {Type} from './type';
|
||||
import {NgZone} from './zone/ng_zone';
|
||||
|
||||
var _devMode: boolean = true;
|
||||
var _runModeLocked: boolean = false;
|
||||
var _platform: PlatformRef;
|
||||
let _devMode: boolean = true;
|
||||
let _runModeLocked: boolean = false;
|
||||
let _platform: PlatformRef;
|
||||
|
||||
/**
|
||||
* Disable Angular's development mode, which turns off assertions and other
|
||||
|
@ -67,13 +67,13 @@ export function isDevMode(): boolean {
|
|||
* @experimental APIs related to application bootstrap are currently under review.
|
||||
*/
|
||||
export function createPlatform(injector: Injector): PlatformRef {
|
||||
if (isPresent(_platform) && !_platform.destroyed) {
|
||||
if (_platform && !_platform.destroyed) {
|
||||
throw new Error(
|
||||
'There can be only one platform. Destroy the previous one to create a new one.');
|
||||
}
|
||||
_platform = injector.get(PlatformRef);
|
||||
const inits: Function[] = <Function[]>injector.get(PLATFORM_INITIALIZER, null);
|
||||
if (isPresent(inits)) inits.forEach(init => init());
|
||||
if (inits) inits.forEach(init => init());
|
||||
return _platform;
|
||||
}
|
||||
|
||||
|
@ -107,14 +107,17 @@ export function createPlatformFactory(
|
|||
* @experimental APIs related to application bootstrap are currently under review.
|
||||
*/
|
||||
export function assertPlatform(requiredToken: any): PlatformRef {
|
||||
var platform = getPlatform();
|
||||
if (isBlank(platform)) {
|
||||
const platform = getPlatform();
|
||||
|
||||
if (!platform) {
|
||||
throw new Error('No platform exists!');
|
||||
}
|
||||
if (isPresent(platform) && isBlank(platform.injector.get(requiredToken, null))) {
|
||||
|
||||
if (!platform.injector.get(requiredToken, null)) {
|
||||
throw new Error(
|
||||
'A platform with a different configuration has been created. Please destroy it first.');
|
||||
}
|
||||
|
||||
return platform;
|
||||
}
|
||||
|
||||
|
@ -124,7 +127,7 @@ export function assertPlatform(requiredToken: any): PlatformRef {
|
|||
* @experimental APIs related to application bootstrap are currently under review.
|
||||
*/
|
||||
export function destroyPlatform(): void {
|
||||
if (isPresent(_platform) && !_platform.destroyed) {
|
||||
if (_platform && !_platform.destroyed) {
|
||||
_platform.destroy();
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +138,7 @@ export function destroyPlatform(): void {
|
|||
* @experimental APIs related to application bootstrap are currently under review.
|
||||
*/
|
||||
export function getPlatform(): PlatformRef {
|
||||
return isPresent(_platform) && !_platform.destroyed ? _platform : null;
|
||||
return _platform && !_platform.destroyed ? _platform : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,9 +227,9 @@ function _callAndReportToErrorHandler(errorHandler: ErrorHandler, callback: () =
|
|||
// rethrow as the exception handler might not do it
|
||||
throw e;
|
||||
});
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
errorHandler.handleError(e);
|
||||
// rethrow as the exception handler might not do it
|
||||
|
@ -238,7 +241,6 @@ function _callAndReportToErrorHandler(errorHandler: ErrorHandler, callback: () =
|
|||
export class PlatformRef_ extends PlatformRef {
|
||||
private _modules: NgModuleRef<any>[] = [];
|
||||
private _destroyListeners: Function[] = [];
|
||||
|
||||
private _destroyed: boolean = false;
|
||||
|
||||
constructor(private _injector: Injector) { super(); }
|
||||
|
@ -253,8 +255,8 @@ export class PlatformRef_ extends PlatformRef {
|
|||
if (this._destroyed) {
|
||||
throw new Error('The platform has already been destroyed!');
|
||||
}
|
||||
ListWrapper.clone(this._modules).forEach((app) => app.destroy());
|
||||
this._destroyListeners.forEach((dispose) => dispose());
|
||||
this._modules.slice().forEach(module => module.destroy());
|
||||
this._destroyListeners.forEach(listener => listener());
|
||||
this._destroyed = true;
|
||||
}
|
||||
|
||||
|
@ -301,7 +303,7 @@ export class PlatformRef_ extends PlatformRef {
|
|||
componentFactoryCallback?: any): Promise<NgModuleRef<M>> {
|
||||
const compilerFactory: CompilerFactory = this.injector.get(CompilerFactory);
|
||||
const compiler = compilerFactory.createCompiler(
|
||||
compilerOptions instanceof Array ? compilerOptions : [compilerOptions]);
|
||||
Array.isArray(compilerOptions) ? compilerOptions : [compilerOptions]);
|
||||
|
||||
// ugly internal api hack: generate host component factories for all declared components and
|
||||
// pass the factories into the callback - this is used by UpdateAdapter to get hold of all
|
||||
|
@ -424,10 +426,10 @@ export class ApplicationRef_ extends ApplicationRef {
|
|||
componentFactory = this._componentFactoryResolver.resolveComponentFactory(componentOrFactory);
|
||||
}
|
||||
this._rootComponentTypes.push(componentFactory.componentType);
|
||||
var compRef = componentFactory.create(this._injector, [], componentFactory.selector);
|
||||
const compRef = componentFactory.create(this._injector, [], componentFactory.selector);
|
||||
compRef.onDestroy(() => { this._unloadComponent(compRef); });
|
||||
var testability = compRef.injector.get(Testability, null);
|
||||
if (isPresent(testability)) {
|
||||
const testability = compRef.injector.get(Testability, null);
|
||||
if (testability) {
|
||||
compRef.injector.get(TestabilityRegistry)
|
||||
.registerApplication(compRef.location.nativeElement, testability);
|
||||
}
|
||||
|
@ -454,7 +456,7 @@ export class ApplicationRef_ extends ApplicationRef {
|
|||
|
||||
/** @internal */
|
||||
_unloadComponent(componentRef: ComponentRef<any>): void {
|
||||
if (!ListWrapper.contains(this._rootComponents, componentRef)) {
|
||||
if (this._rootComponents.indexOf(componentRef) == -1) {
|
||||
return;
|
||||
}
|
||||
this.unregisterChangeDetector(componentRef.changeDetectorRef);
|
||||
|
@ -466,7 +468,7 @@ export class ApplicationRef_ extends ApplicationRef {
|
|||
throw new Error('ApplicationRef.tick is called recursively');
|
||||
}
|
||||
|
||||
var s = ApplicationRef_._tickScope();
|
||||
const scope = ApplicationRef_._tickScope();
|
||||
try {
|
||||
this._runningTick = true;
|
||||
this._changeDetectorRefs.forEach((detector) => detector.detectChanges());
|
||||
|
@ -475,13 +477,13 @@ export class ApplicationRef_ extends ApplicationRef {
|
|||
}
|
||||
} finally {
|
||||
this._runningTick = false;
|
||||
wtfLeave(s);
|
||||
wtfLeave(scope);
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
// TODO(alxhub): Dispose of the NgZone.
|
||||
ListWrapper.clone(this._rootComponents).forEach((ref) => ref.destroy());
|
||||
this._rootComponents.slice().forEach((component) => component.destroy());
|
||||
}
|
||||
|
||||
get componentTypes(): Type<any>[] { return this._rootComponentTypes; }
|
||||
|
|
|
@ -34,7 +34,7 @@ export function _appIdRandomProviderFactory() {
|
|||
export const APP_ID_RANDOM_PROVIDER = {
|
||||
provide: APP_ID,
|
||||
useFactory: _appIdRandomProviderFactory,
|
||||
deps: <any[]>[]
|
||||
deps: <any[]>[],
|
||||
};
|
||||
|
||||
function _randomChar(): string {
|
||||
|
|
|
@ -10,7 +10,6 @@ import {APP_ID} from '../application_tokens';
|
|||
import {devModeEqual} from '../change_detection/change_detection';
|
||||
import {UNINITIALIZED} from '../change_detection/change_detection_util';
|
||||
import {Inject, Injectable} from '../di';
|
||||
import {ListWrapper} from '../facade/collection';
|
||||
import {isBlank, isPresent, looseIdentical} from '../facade/lang';
|
||||
import {ViewEncapsulation} from '../metadata/view';
|
||||
import {RenderComponentType, Renderer, RootRenderer} from '../render/api';
|
||||
|
|
|
@ -15,8 +15,6 @@ import {Attribute, ContentChild, ContentChildren, Query, ViewChild, ViewChildren
|
|||
import {Component, Directive, HostBinding, HostListener, Input, Output, Pipe} from './metadata/directives';
|
||||
import {ModuleWithProviders, NgModule, SchemaMetadata} from './metadata/ng_module';
|
||||
import {ViewEncapsulation} from './metadata/view';
|
||||
import {Type} from './type';
|
||||
import {TypeDecorator, makeParamDecorator, makePropDecorator} from './util/decorators';
|
||||
|
||||
export {ANALYZE_FOR_ENTRY_COMPONENTS, Attribute, ContentChild, ContentChildDecorator, ContentChildren, ContentChildrenDecorator, Query, ViewChild, ViewChildDecorator, ViewChildren, ViewChildrenDecorator} from './metadata/di';
|
||||
export {Component, ComponentDecorator, Directive, DirectiveDecorator, HostBinding, HostListener, Input, Output, Pipe} from './metadata/directives';
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
*/
|
||||
|
||||
import {AnimationEntryMetadata} from '../animation/metadata';
|
||||
import {Type} from '../type';
|
||||
|
||||
|
||||
/**
|
||||
* Defines template and style encapsulation options available for Component's {@link Component}.
|
||||
|
@ -46,13 +44,6 @@ export var VIEW_ENCAPSULATION_VALUES =
|
|||
/**
|
||||
* Metadata properties available for configuring Views.
|
||||
*
|
||||
* Each Angular component requires a single `@Component` and at least one `@View` annotation. The
|
||||
* `@View` annotation specifies the HTML template to use, and lists the directives that are active
|
||||
* within the template.
|
||||
*
|
||||
* When a component is instantiated, the template is loaded into the component's shadow root, and
|
||||
* the expressions and statements in the template are evaluated against the component.
|
||||
*
|
||||
* For details on the `@Component` annotation, see {@link Component}.
|
||||
*
|
||||
* ### Example
|
||||
|
@ -61,7 +52,6 @@ export var VIEW_ENCAPSULATION_VALUES =
|
|||
* @Component({
|
||||
* selector: 'greet',
|
||||
* template: 'Hello {{name}}!',
|
||||
* directives: [GreetUser, Bold]
|
||||
* })
|
||||
* class Greet {
|
||||
* name: string;
|
||||
|
@ -73,46 +63,23 @@ export var VIEW_ENCAPSULATION_VALUES =
|
|||
* ```
|
||||
*
|
||||
* @deprecated Use Component instead.
|
||||
*
|
||||
* {@link Component}
|
||||
*/
|
||||
export class ViewMetadata {
|
||||
/**
|
||||
* Specifies a template URL for an Angular component.
|
||||
*
|
||||
* NOTE: Only one of `templateUrl` or `template` can be defined per View.
|
||||
*
|
||||
* <!-- TODO: what's the url relative to? -->
|
||||
*/
|
||||
/** {@link Component.templateUrl} */
|
||||
templateUrl: string;
|
||||
|
||||
/**
|
||||
* Specifies an inline template for an Angular component.
|
||||
*
|
||||
* NOTE: Only one of `templateUrl` or `template` can be defined per View.
|
||||
*/
|
||||
/** {@link Component.template} */
|
||||
template: string;
|
||||
|
||||
/**
|
||||
* Specifies stylesheet URLs for an Angular component.
|
||||
*
|
||||
* <!-- TODO: what's the url relative to? -->
|
||||
*/
|
||||
/** {@link Component.stylesUrl} */
|
||||
styleUrls: string[];
|
||||
|
||||
/**
|
||||
* Specifies an inline stylesheet for an Angular component.
|
||||
*/
|
||||
/** {@link Component.styles} */
|
||||
styles: string[];
|
||||
|
||||
/**
|
||||
* Specify how the template and the styles should be encapsulated.
|
||||
* The default is {@link ViewEncapsulation#Emulated `ViewEncapsulation.Emulated`} if the view
|
||||
* has styles,
|
||||
* otherwise {@link ViewEncapsulation#None `ViewEncapsulation.None`}.
|
||||
*/
|
||||
/** {@link Component.encapsulation} */
|
||||
encapsulation: ViewEncapsulation;
|
||||
|
||||
/** {@link Component.animation} */
|
||||
animations: AnimationEntryMetadata[];
|
||||
|
||||
/** {@link Component.interpolation} */
|
||||
interpolation: [string, string];
|
||||
|
||||
constructor(
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import {PlatformRef, PlatformRef_, createPlatformFactory} from './application_ref';
|
||||
import {Console} from './console';
|
||||
import {ClassProvider, ExistingProvider, FactoryProvider, Provider, TypeProvider, ValueProvider} from './di';
|
||||
import {Provider} from './di';
|
||||
import {Reflector, reflector} from './reflection/reflection';
|
||||
import {ReflectorReader} from './reflection/reflector_reader';
|
||||
import {TestabilityRegistry} from './testability/testability';
|
||||
|
@ -18,9 +18,12 @@ function _reflector(): Reflector {
|
|||
}
|
||||
|
||||
const _CORE_PLATFORM_PROVIDERS: Provider[] = [
|
||||
PlatformRef_, {provide: PlatformRef, useExisting: PlatformRef_},
|
||||
PlatformRef_,
|
||||
{provide: PlatformRef, useExisting: PlatformRef_},
|
||||
{provide: Reflector, useFactory: _reflector, deps: []},
|
||||
{provide: ReflectorReader, useExisting: Reflector}, TestabilityRegistry, Console
|
||||
{provide: ReflectorReader, useExisting: Reflector},
|
||||
TestabilityRegistry,
|
||||
Console,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @stable
|
||||
*/
|
||||
export var Type = Function;
|
||||
export const Type = Function;
|
||||
|
||||
|
||||
export interface Type<T> extends Function { new (...args: any[]): T; }
|
||||
|
|
|
@ -916,7 +916,7 @@ export declare const TRANSLATIONS_FORMAT: OpaqueToken;
|
|||
export declare function trigger(name: string, animation: AnimationMetadata[]): AnimationEntryMetadata;
|
||||
|
||||
/** @stable */
|
||||
export declare var Type: FunctionConstructor;
|
||||
export declare const Type: FunctionConstructor;
|
||||
|
||||
/** @stable */
|
||||
export interface TypeDecorator {
|
||||
|
|
Loading…
Reference in New Issue