refactor(core): move APP_ID from render/dom/dom_tokens into application_tokens

This commit is contained in:
Tobias Bosch 2015-10-02 09:53:57 -07:00
parent 6b5d345a2b
commit 13161ae5aa
12 changed files with 46 additions and 45 deletions

View File

@ -9,6 +9,5 @@ export 'package:angular2/core.dart' hide forwardRef, resolveForwardRef, ForwardR
export 'package:angular2/profile.dart';
export 'package:angular2/lifecycle_hooks.dart';
export 'package:angular2/src/core/application_ref.dart';
export 'package:angular2/src/core/application_tokens.dart' hide APP_COMPONENT_REF_PROMISE;
export 'package:angular2/src/core/render/dom/dom_tokens.dart' hide APP_ID_RANDOM_BINDING;
export 'package:angular2/src/core/render/dom/dom_tokens.dart' hide APP_ID_RANDOM_BINDING;
export 'package:angular2/src/core/application_tokens.dart' hide APP_COMPONENT_REF_PROMISE, APP_ID_RANDOM_BINDING;
export 'package:angular2/src/core/render/dom/dom_tokens.dart';

View File

@ -6,7 +6,7 @@ import {compilerBindings} from 'angular2/src/core/compiler/compiler';
import {commonBootstrap} from './application_common';
import {ComponentRef} from './linker/dynamic_component_loader';
export {APP_COMPONENT} from './application_tokens';
export {APP_COMPONENT, APP_ID} from './application_tokens';
export {platform} from './application_common';
export {
PlatformRef,

View File

@ -30,7 +30,8 @@ import {
} from 'angular2/src/core/linker/dynamic_component_loader';
import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability';
import {Renderer} from 'angular2/src/core/render/api';
import {DomRenderer, DOCUMENT, APP_ID_RANDOM_BINDING} from 'angular2/src/core/render/render';
import {DomRenderer, DOCUMENT} from 'angular2/src/core/render/render';
import {APP_ID_RANDOM_BINDING} from 'angular2/src/core/application_tokens';
import {ElementSchemaRegistry} from 'angular2/src/core/compiler/schema/element_schema_registry';
import {
DomElementSchemaRegistry

View File

@ -1,7 +1,11 @@
import {NgZone} from 'angular2/src/core/zone/ng_zone';
import {Type, isBlank, isPresent, assertionsEnabled} from 'angular2/src/core/facade/lang';
import {bind, Binding, Injector, OpaqueToken} from 'angular2/src/core/di';
import {APP_COMPONENT_REF_PROMISE, APP_COMPONENT} from './application_tokens';
import {
APP_COMPONENT_REF_PROMISE,
APP_COMPONENT,
APP_ID_RANDOM_BINDING
} from './application_tokens';
import {Promise, PromiseWrapper, PromiseCompleter} from 'angular2/src/core/facade/async';
import {ListWrapper} from 'angular2/src/core/facade/collection';
import {Reflector, reflector} from 'angular2/src/core/reflection/reflection';
@ -36,9 +40,6 @@ import {ViewResolver} from './linker/view_resolver';
import {DirectiveResolver} from './linker/directive_resolver';
import {PipeResolver} from './linker/pipe_resolver';
import {UrlResolver} from 'angular2/src/core/compiler/url_resolver';
import {
APP_ID_RANDOM_BINDING,
} from 'angular2/src/core/render/render';
import {Compiler} from 'angular2/src/core/linker/compiler';
/**

View File

@ -1,5 +1,5 @@
import {OpaqueToken} from 'angular2/src/core/di';
import {CONST_EXPR} from 'angular2/src/core/facade/lang';
import {OpaqueToken, Binding} from 'angular2/src/core/di';
import {CONST_EXPR, Math, StringWrapper} from 'angular2/src/core/facade/lang';
/**
* @private
@ -24,3 +24,28 @@ export const APP_COMPONENT_REF_PROMISE = CONST_EXPR(new OpaqueToken('Promise<Com
* ```
*/
export const APP_COMPONENT: OpaqueToken = CONST_EXPR(new OpaqueToken('AppComponent'));
/**
* A DI Token representing a unique string id assigned to the application by Angular and used
* primarily for prefixing application attributes and CSS styles when
* {@link ViewEncapsulation#Emulated} is being used.
*
* If you need to avoid randomly generated value to be used as an application id, you can provide
* a custom value via a DI binding <!-- TODO: provider --> configuring the root {@link Injector}
* using this token.
*/
export const APP_ID: OpaqueToken = CONST_EXPR(new OpaqueToken('AppId'));
function _appIdRandomBindingFactory() {
return `${_randomChar()}${_randomChar()}${_randomChar()}`;
}
/**
* Bindings that will generate a random APP_ID_TOKEN.
*/
export const APP_ID_RANDOM_BINDING: Binding =
CONST_EXPR(new Binding(APP_ID, {toFactory: _appIdRandomBindingFactory, deps: []}));
function _randomChar(): string {
return StringWrapper.fromCharCode(97 + Math.floor(Math.random() * 25));
}

View File

@ -23,7 +23,7 @@ import {CommandCompiler} from './command_compiler';
import {TemplateParser} from './template_parser';
import {TemplateNormalizer} from './template_normalizer';
import {RuntimeMetadataResolver} from './runtime_metadata';
import {APP_ID} from 'angular2/src/core/render/dom/dom_tokens';
import {APP_ID} from 'angular2/src/core/application_tokens';
import {TEMPLATE_COMMANDS_MODULE_REF} from './command_compiler';
import {

View File

@ -32,7 +32,7 @@ import {
} from './template_commands';
import {Renderer} from 'angular2/render';
import {APP_ID} from 'angular2/src/core/render/dom/dom_tokens';
import {APP_ID} from 'angular2/src/core/application_tokens';
@Injectable()

View File

@ -8,7 +8,6 @@ export {
RenderFragmentRef,
RenderViewWithFragments,
DOCUMENT,
APP_ID,
RenderTemplateCmd,
RenderCommandVisitor,
RenderTextCmd,

View File

@ -1,5 +1,5 @@
import {OpaqueToken, Binding} from 'angular2/src/core/di';
import {CONST_EXPR, StringWrapper, Math} from 'angular2/src/core/facade/lang';
import {OpaqueToken} from 'angular2/src/core/di';
import {CONST_EXPR} from 'angular2/src/core/facade/lang';
/**
* A DI Token representing the main rendering context. In a browser this is the DOM Document.
@ -8,28 +8,3 @@ import {CONST_EXPR, StringWrapper, Math} from 'angular2/src/core/facade/lang';
* Contexts are not the same (e.g. when running the application into a Web Worker).
*/
export const DOCUMENT: OpaqueToken = CONST_EXPR(new OpaqueToken('DocumentToken'));
/**
* A DI Token representing a unique string id assigned to the application by Angular and used
* primarily for prefixing application attributes and CSS styles when
* {@link ViewEncapsulation#Emulated} is being used.
*
* If you need to avoid randomly generated value to be used as an application id, you can provide
* a custom value via a DI binding <!-- TODO: provider --> configuring the root {@link Injector}
* using this token.
*/
export const APP_ID: OpaqueToken = CONST_EXPR(new OpaqueToken('AppId'));
function _appIdRandomBindingFactory() {
return `${_randomChar()}${_randomChar()}${_randomChar()}`;
}
/**
* Bindings that will generate a random APP_ID_TOKEN.
*/
export const APP_ID_RANDOM_BINDING: Binding =
CONST_EXPR(new Binding(APP_ID, {toFactory: _appIdRandomBindingFactory, deps: []}));
function _randomChar(): string {
return StringWrapper.fromCharCode(97 + Math.floor(Math.random() * 25));
}

View File

@ -55,11 +55,11 @@ import {Renderer} from 'angular2/src/core/render/api';
import {
DomRenderer,
DOCUMENT,
APP_ID,
SharedStylesHost,
DomSharedStylesHost
} from 'angular2/src/core/render/render';
import {ElementSchemaRegistry} from 'angular2/src/core/compiler/schema/element_schema_registry';
import {APP_ID} from 'angular2/src/core/application_tokens' import { ElementSchemaRegistry }
from 'angular2/src/core/compiler/schema/element_schema_registry';
import {
DomElementSchemaRegistry
} from 'angular2/src/core/compiler/schema/dom_element_schema_registry';

View File

@ -18,7 +18,8 @@ import {HammerGesturesPlugin} from 'angular2/src/core/render/dom/events/hammer_g
import {AppViewPool, APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/linker/view_pool';
import {Renderer} from 'angular2/src/core/render/api';
import {AppRootUrl} from 'angular2/src/core/compiler/app_root_url';
import {DomRenderer, DOCUMENT, APP_ID_RANDOM_BINDING} from 'angular2/src/core/render/render';
import {DomRenderer, DOCUMENT} from 'angular2/src/core/render/render';
import {APP_ID_RANDOM_BINDING} from 'angular2/src/core/application_tokens';
import {ElementSchemaRegistry} from 'angular2/src/core/compiler/schema/element_schema_registry';
import {
DomElementSchemaRegistry

View File

@ -50,7 +50,7 @@ import {
codeGenExportVariable,
MODULE_SUFFIX
} from 'angular2/src/core/compiler/util';
import {APP_ID} from 'angular2/src/core/render/dom/dom_tokens';
import {APP_ID} from 'angular2/src/core/application_tokens';
// Attention: This path has to point to this test file!
const THIS_MODULE_ID = 'angular2/test/core/compiler/template_compiler_spec';