From ea6673947cd631dd823975321cd2e6ab9abaf504 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 14 Aug 2015 10:03:45 -0700 Subject: [PATCH] refactor: rename annotations to metadata BREAKING CHANGE (maybe) Well as long as our customers use public API this should not be a breaking change, but we have changed import structure as well as internal names, so it could be breaking. import: angular2/annotations => angular2/metadata Classes: *Annotations => *Metadata renderer.DirectiveMetadata => renderer.RendererDirectiveMetadata renderer.ElementBinder => renderer.RendererElementBinder impl.Directive => impl.DirectiveMetadata impl.Component => impl.ComponentMetadata impl.View => impl.ViewMetadata Closes #3660 --- docs/public-docs-package/index.js | 2 +- modules/angular2/angular2.ts | 2 +- modules/angular2/angular2_exports.ts | 2 +- modules/angular2/annotations.ts | 50 -- modules/angular2/bootstrap.ts | 2 +- modules/angular2/metadata.dart | 4 + modules/angular2/metadata.ts | 48 ++ modules/angular2/render.ts | 2 +- .../change_detection/change_detection_util.ts | 3 +- .../src/core/annotations/annotations.dart | 8 - .../src/core/annotations/annotations.ts | 11 - .../src/core/annotations/decorators.dart | 5 - modules/angular2/src/core/annotations/di.dart | 3 - modules/angular2/src/core/annotations/di.ts | 5 - .../angular2/src/core/annotations/view.dart | 3 - modules/angular2/src/core/annotations/view.ts | 1 - .../angular2/src/core/application_common.ts | 4 +- .../angular2/src/core/compiler/compiler.ts | 38 +- .../src/core/compiler/component_url_mapper.ts | 2 +- .../directive_lifecycle_reflector.dart | 4 +- .../compiler/directive_lifecycle_reflector.ts | 4 +- .../src/core/compiler/directive_resolver.ts | 10 +- .../src/core/compiler/element_injector.ts | 46 +- .../src/core/compiler/pipe_resolver.ts | 10 +- .../src/core/compiler/proto_view_factory.ts | 82 +-- .../src/core/compiler/view_resolver.ts | 8 +- modules/angular2/src/core/metadata.dart | 97 +++ .../decorators.ts => metadata.ts} | 101 +-- .../core/{annotations_impl => metadata}/di.ts | 6 +- .../annotations.ts => metadata/directives.ts} | 20 +- .../{annotations_impl => metadata}/view.ts | 4 +- .../angular2/src/core/pipes/pipe_binding.ts | 6 +- modules/angular2/src/core/pipes/pipes.ts | 2 +- modules/angular2/src/directives/ng_class.ts | 2 +- modules/angular2/src/directives/ng_for.ts | 2 +- modules/angular2/src/directives/ng_if.ts | 2 +- .../src/directives/ng_non_bindable.ts | 2 +- modules/angular2/src/directives/ng_style.ts | 2 +- modules/angular2/src/directives/ng_switch.ts | 2 +- .../directives/checkbox_value_accessor.ts | 2 +- .../directives/default_value_accessor.ts | 2 +- .../src/forms/directives/ng_control_group.ts | 2 +- .../src/forms/directives/ng_control_name.ts | 2 +- .../angular2/src/forms/directives/ng_form.ts | 2 +- .../src/forms/directives/ng_form_control.ts | 2 +- .../src/forms/directives/ng_form_model.ts | 2 +- .../angular2/src/forms/directives/ng_model.ts | 2 +- .../select_control_value_accessor.ts | 2 +- .../src/forms/directives/validators.ts | 2 +- .../angular2/src/mock/view_resolver_mock.ts | 23 +- modules/angular2/src/pipes/async_pipe.ts | 4 +- modules/angular2/src/pipes/date_pipe.ts | 2 +- modules/angular2/src/pipes/json_pipe.ts | 2 +- modules/angular2/src/pipes/limit_to_pipe.ts | 2 +- modules/angular2/src/pipes/lowercase_pipe.ts | 2 +- modules/angular2/src/pipes/number_pipe.ts | 2 +- modules/angular2/src/pipes/uppercase_pipe.ts | 2 +- modules/angular2/src/render/api.ts | 20 +- .../src/render/dom/compiler/compiler.ts | 4 +- .../render/dom/compiler/directive_parser.ts | 6 +- modules/angular2/src/render/dom/convert.ts | 8 +- .../src/render/dom/view/proto_view_builder.ts | 53 +- modules/angular2/src/router/router_link.ts | 2 +- modules/angular2/src/router/router_outlet.ts | 2 +- .../src/test_lib/test_component_builder.ts | 14 +- .../transform/common/annotation_matcher.dart | 31 +- .../common/directive_metadata_reader.dart | 16 +- .../transform/common/interface_matcher.dart | 10 +- .../src/transform/common/ng_meta.dart | 4 +- .../src/transform/common/registered_type.dart | 4 +- .../directive_processor/visitors.dart | 2 +- .../view_definition_creator.dart | 10 +- modules/angular2/src/util/decorators.dart | 2 +- modules/angular2/src/util/decorators.ts | 2 +- .../src/web-workers/shared/serializer.ts | 32 +- modules/angular2/src/web-workers/ui/impl.ts | 4 +- .../src/web-workers/worker/renderer.ts | 6 +- .../transform/bind_generator/simple.dart | 2 +- .../transform/directive_linker/simple.dart | 4 +- .../transform/directive_processor/simple.dart | 2 +- .../angular2/test/core/application_spec.ts | 2 +- .../test/core/compiler/compiler_spec.ts | 159 ++--- .../core/compiler/directive_lifecycle_spec.ts | 54 +- .../directive_metadata_reader_spec.ts | 7 +- .../compiler/dynamic_component_loader_spec.ts | 46 +- .../core/compiler/element_injector_spec.ts | 55 +- .../test/core/compiler/integration_spec.ts | 622 +++++++++--------- .../compiler/projection_integration_spec.ts | 213 +++--- .../core/compiler/proto_view_factory_spec.ts | 79 +-- .../core/compiler/query_integration_spec.ts | 2 +- .../core/compiler/view_manager_utils_spec.ts | 2 +- .../directive_lifecycle_integration_spec.ts | 3 +- .../test/core/forward_ref_integration_spec.ts | 2 +- .../decorators_spec.dart | 0 .../decorators_spec.ts | 0 .../test/core/pipes/pipe_binding_spec.ts | 2 +- .../angular2/test/core/pipes/pipes_spec.ts | 2 +- .../angular2/test/debug/debug_element_spec.ts | 2 +- .../debug/debug_element_view_listener_spec.ts | 2 +- .../test/mock/view_resolver_mock_spec.ts | 10 +- modules/angular2/test/render/api_spec.ts | 4 +- .../dom/compiler/compiler_common_tests.ts | 14 +- .../dom/compiler/directive_parser_spec.ts | 42 +- .../angular2/test/render/dom/convert_spec.ts | 12 +- .../dom/dom_renderer_integration_spec.ts | 6 +- .../angular2/test/render/dom/dom_testbed.ts | 7 +- .../proto_view_merger_integration_spec.ts | 18 +- modules/angular2/test/router/outlet_spec.ts | 11 +- .../angular2/test/router/route_config_spec.ts | 2 +- .../test/router/router_integration_spec.ts | 2 +- .../test_lib/test_component_builder_spec.ts | 10 +- .../basic_bind_files/bar.ng_deps.dart | 2 +- .../expected/bar.ng_deps.dart | 2 +- .../expected/soup.ng_deps.dart | 2 +- .../soup.ng_deps.dart | 2 +- .../events_files/bar.ng_deps.dart | 2 +- .../events_files/expected/bar.ng_deps.dart | 2 +- .../test/transform/common/ng_meta_test.dart | 8 +- .../simple_export_files/bar.ng_deps.dart | 2 +- .../expected/bar.ng_deps.dart | 2 +- .../expected/foo.ng_deps.dart | 2 +- .../simple_export_files/foo.ng_deps.dart | 2 +- .../simple_files/bar.ng_deps.dart | 2 +- .../simple_files/expected/bar.ng_deps.dart | 2 +- .../simple_files/expected/foo.ng_deps.dart | 2 +- .../simple_files/foo.ng_deps.dart | 2 +- .../absolute_export_files/bar.ng_deps.dart | 2 +- .../absolute_export_files/foo.ng_deps.dart | 2 +- .../adjacent_strings_files/foo.ng_deps.dart | 2 +- .../directive_aliases_files/bar.ng_deps.dart | 2 +- .../directive_aliases_files/foo.ng_deps.dart | 2 +- .../export_files/bar.ng_deps.dart | 2 +- .../export_files/foo.ng_deps.dart | 2 +- .../recursive_export_files/bar.ng_deps.dart | 2 +- .../recursive_export_files/baz.ng_deps.dart | 2 +- .../recursive_export_files/foo.ng_deps.dart | 2 +- .../simple_files/foo.ng_deps.dart | 2 +- .../expected/soup.ng_deps.dart | 2 +- .../interface_chain_files/soup.dart | 2 +- .../expected/soup.ng_deps.dart | 2 +- .../interface_lifecycle_files/soup.dart | 2 +- .../expected/soup.ng_deps.dart | 2 +- .../interfaces_files/soup.dart | 2 +- .../expected/soup.ng_deps.dart | 2 +- .../soup.dart | 2 +- .../expected/main.ng_deps.dart | 2 +- .../multiple_part_files/main.dart | 2 +- .../expected/soup.ng_deps.dart | 2 +- .../parameter_metadata/soup.dart | 2 +- .../part_files/expected/main.ng_deps.dart | 2 +- .../directive_processor/part_files/main.dart | 2 +- .../expected/soup.ng_deps.dart | 2 +- .../soup.dart | 2 +- .../expected/soup.ng_deps.dart | 2 +- .../superclass_files/soup.dart | 2 +- .../expected/soup.ng_deps.dart | 2 +- .../superclass_lifecycle_files/soup.dart | 2 +- .../test/transform/integration/all_tests.dart | 7 +- .../integration/list_of_types_files/bar.dart | 2 +- .../expected/bar.ng_deps.dart | 2 +- .../simple_annotation_files/bar.dart | 2 +- .../expected/bar.ng_deps.dart | 2 +- .../integration/synthetic_ctor_files/bar.dart | 2 +- .../expected/bar.ng_deps.dart | 2 +- .../two_annotations_files/bar.dart | 3 +- .../expected/bar.ng_deps.dart | 3 +- .../integration/two_deps_files/bar.dart | 2 +- .../two_deps_files/expected/bar.ng_deps.dart | 2 +- .../test/web-workers/worker/renderer_spec.ts | 6 +- .../src/compiler/compiler_benchmark.ts | 7 +- .../analyzer_plugin/lib/src/tasks.dart | 12 +- .../test/tasks_test.server.spec.dart | 10 +- 172 files changed, 1287 insertions(+), 1173 deletions(-) delete mode 100644 modules/angular2/annotations.ts create mode 100644 modules/angular2/metadata.dart create mode 100644 modules/angular2/metadata.ts delete mode 100644 modules/angular2/src/core/annotations/annotations.dart delete mode 100644 modules/angular2/src/core/annotations/annotations.ts delete mode 100644 modules/angular2/src/core/annotations/decorators.dart delete mode 100644 modules/angular2/src/core/annotations/di.dart delete mode 100644 modules/angular2/src/core/annotations/di.ts delete mode 100644 modules/angular2/src/core/annotations/view.dart delete mode 100644 modules/angular2/src/core/annotations/view.ts create mode 100644 modules/angular2/src/core/metadata.dart rename modules/angular2/src/core/{annotations/decorators.ts => metadata.ts} (76%) rename modules/angular2/src/core/{annotations_impl => metadata}/di.ts (93%) rename modules/angular2/src/core/{annotations_impl/annotations.ts => metadata/directives.ts} (97%) rename modules/angular2/src/core/{annotations_impl => metadata}/view.ts (98%) rename modules/angular2/test/core/{annotations => metadata}/decorators_spec.dart (100%) rename modules/angular2/test/core/{annotations => metadata}/decorators_spec.ts (100%) diff --git a/docs/public-docs-package/index.js b/docs/public-docs-package/index.js index 08e42b77e9..3ebb3c2571 100644 --- a/docs/public-docs-package/index.js +++ b/docs/public-docs-package/index.js @@ -5,7 +5,7 @@ module.exports = new Package('angular-v2-public-docs', [basePackage]) .config(function(readTypeScriptModules) { readTypeScriptModules.sourceFiles = [ - 'angular2/annotations.ts', + 'angular2/metadata.ts', 'angular2/change_detection.ts', 'angular2/core.ts', 'angular2/di.ts', diff --git a/modules/angular2/angular2.ts b/modules/angular2/angular2.ts index 640a4d18dd..d8124b4bab 100644 --- a/modules/angular2/angular2.ts +++ b/modules/angular2/angular2.ts @@ -7,7 +7,7 @@ export {commonBootstrap as bootstrap} from 'angular2/src/core/application_common // angular2_exports.ts. Re-exporting from angular2_exports.ts causes systemjs // to resolve imports very very very slowly. See also a similar notice in // bootstrap.ts -export * from './annotations'; +export * from './metadata'; export * from './change_detection'; export * from './core'; export * from './di'; diff --git a/modules/angular2/angular2_exports.ts b/modules/angular2/angular2_exports.ts index ed8c911a4b..e781b14e12 100644 --- a/modules/angular2/angular2_exports.ts +++ b/modules/angular2/angular2_exports.ts @@ -1,4 +1,4 @@ -export * from './annotations'; +export * from './metadata'; export * from './change_detection'; export * from './core'; export * from './di'; diff --git a/modules/angular2/annotations.ts b/modules/angular2/annotations.ts deleted file mode 100644 index bb17a972ad..0000000000 --- a/modules/angular2/annotations.ts +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @module - * @description - * - * Annotations provide the additional information that Angular requires in order to run your - * application. This module - * contains {@link Component}, {@link Directive}, and {@link View} annotations, as well as - * the {@link Host} annotation that is used by Angular to resolve dependencies. - * - */ - -export { - ComponentAnnotation, - DirectiveAnnotation, - PipeAnnotation, - LifecycleEvent -} from './src/core/annotations/annotations'; - -export {ViewAnnotation, ViewEncapsulation} from 'angular2/src/core/annotations/view'; -export {QueryAnnotation, AttributeAnnotation} from 'angular2/src/core/annotations/di'; - -export { - OnAllChangesDone, - OnChange, - OnDestroy, - OnInit, - OnCheck -} from 'angular2/src/core/compiler/interfaces'; - - -export {Class, ClassDefinition, TypeDecorator} from 'angular2/src/util/decorators'; - -export { - Attribute, - AttributeFactory, - Component, - ComponentDecorator, - ComponentFactory, - Directive, - DirectiveDecorator, - DirectiveFactory, - View, - ViewDecorator, - ViewFactory, - Query, - QueryFactory, - ViewQuery, - Pipe, - PipeFactory -} from 'angular2/src/core/annotations/decorators'; diff --git a/modules/angular2/bootstrap.ts b/modules/angular2/bootstrap.ts index ddc827d5de..76f53dbada 100644 --- a/modules/angular2/bootstrap.ts +++ b/modules/angular2/bootstrap.ts @@ -7,7 +7,7 @@ export {bootstrap} from 'angular2/src/core/application'; // angular2_exports.ts. Re-exporting from angular2_exports.ts causes systemjs // to resolve imports very very very slowly. See also a similar notice in // angular2.ts -export * from './annotations'; +export * from './metadata'; export * from './change_detection'; export * from './core'; export * from './di'; diff --git a/modules/angular2/metadata.dart b/modules/angular2/metadata.dart new file mode 100644 index 0000000000..81484884f2 --- /dev/null +++ b/modules/angular2/metadata.dart @@ -0,0 +1,4 @@ +library angular2.metadata; + +export 'package:angular2/src/core/metadata.dart'; +export 'package:angular2/src/core/compiler/interfaces.dart'; diff --git a/modules/angular2/metadata.ts b/modules/angular2/metadata.ts new file mode 100644 index 0000000000..7223a51b10 --- /dev/null +++ b/modules/angular2/metadata.ts @@ -0,0 +1,48 @@ +/** + * @module + * @description + * + * Annotations provide the additional information that Angular requires in order to run your + * application. This module + * contains {@link ComponentMetadata}, {@link DirectiveMetadata}, and {@link ViewMetadata} + * annotations, as well as + * the {@link Host} annotation that is used by Angular to resolve dependencies. + * + */ + +export { + ComponentMetadata, + DirectiveMetadata, + PipeMetadata, + LifecycleEvent, + ViewMetadata, + ViewEncapsulation, + QueryMetadata, + AttributeMetadata, + Attribute, + AttributeFactory, + Component, + ComponentDecorator, + ComponentFactory, + Directive, + DirectiveDecorator, + DirectiveFactory, + View, + ViewDecorator, + ViewFactory, + Query, + QueryFactory, + ViewQuery, + Pipe, + PipeFactory +} from './src/core/metadata'; + +export { + OnAllChangesDone, + OnChange, + OnDestroy, + OnInit, + OnCheck +} from './src/core/compiler/interfaces'; + +export {Class, ClassDefinition, TypeDecorator} from './src/util/decorators'; diff --git a/modules/angular2/render.ts b/modules/angular2/render.ts index df60f7bcce..f0b3f69e8e 100644 --- a/modules/angular2/render.ts +++ b/modules/angular2/render.ts @@ -5,7 +5,7 @@ */ export { - DirectiveMetadata, + RenderDirectiveMetadata, DomRenderer, RenderEventDispatcher, Renderer, diff --git a/modules/angular2/src/change_detection/change_detection_util.ts b/modules/angular2/src/change_detection/change_detection_util.ts index f6d6777b6d..3bf63216c5 100644 --- a/modules/angular2/src/change_detection/change_detection_util.ts +++ b/modules/angular2/src/change_detection/change_detection_util.ts @@ -6,7 +6,8 @@ import {implementsOnDestroy} from './pipe_lifecycle_reflector'; /** - * Indicates that the result of a {@link Pipe} transformation has changed even though the reference + * Indicates that the result of a {@link PipeMetadata} transformation has changed even though the + * reference * has not changed. * * The wrapped value will be unwrapped by change detection, and the unwrapped value will be stored. diff --git a/modules/angular2/src/core/annotations/annotations.dart b/modules/angular2/src/core/annotations/annotations.dart deleted file mode 100644 index cc4f68947d..0000000000 --- a/modules/angular2/src/core/annotations/annotations.dart +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This indirection is needed for TS compilation path. - * See comment in annotations.es6. - */ - -library angular2.core.annotations.annotations; - -export "../annotations_impl/annotations.dart"; diff --git a/modules/angular2/src/core/annotations/annotations.ts b/modules/angular2/src/core/annotations/annotations.ts deleted file mode 100644 index 8e11e0eb54..0000000000 --- a/modules/angular2/src/core/annotations/annotations.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * This indirection is needed to free up Component, etc symbols in the public API - * to be used by the decorator versions of these annotations. - */ - -export { - Component as ComponentAnnotation, - Directive as DirectiveAnnotation, - Pipe as PipeAnnotation, - LifecycleEvent -} from '../annotations_impl/annotations'; diff --git a/modules/angular2/src/core/annotations/decorators.dart b/modules/angular2/src/core/annotations/decorators.dart deleted file mode 100644 index f2976668a8..0000000000 --- a/modules/angular2/src/core/annotations/decorators.dart +++ /dev/null @@ -1,5 +0,0 @@ -library angular2.core.decorators; - -export '../annotations_impl/annotations.dart'; -export '../annotations_impl/view.dart'; -export '../annotations_impl/di.dart'; diff --git a/modules/angular2/src/core/annotations/di.dart b/modules/angular2/src/core/annotations/di.dart deleted file mode 100644 index 8b182acb0d..0000000000 --- a/modules/angular2/src/core/annotations/di.dart +++ /dev/null @@ -1,3 +0,0 @@ -library angular2.core.annotations.di; - -export "../annotations_impl/di.dart"; diff --git a/modules/angular2/src/core/annotations/di.ts b/modules/angular2/src/core/annotations/di.ts deleted file mode 100644 index 61a23c1c9b..0000000000 --- a/modules/angular2/src/core/annotations/di.ts +++ /dev/null @@ -1,5 +0,0 @@ -export { - Query as QueryAnnotation, - ViewQuery as ViewQueryAnnotation, - Attribute as AttributeAnnotation, -} from '../annotations_impl/di'; diff --git a/modules/angular2/src/core/annotations/view.dart b/modules/angular2/src/core/annotations/view.dart deleted file mode 100644 index 30171a89dc..0000000000 --- a/modules/angular2/src/core/annotations/view.dart +++ /dev/null @@ -1,3 +0,0 @@ -library angular2.core.annotations.view; - -export "../annotations_impl/view.dart"; diff --git a/modules/angular2/src/core/annotations/view.ts b/modules/angular2/src/core/annotations/view.ts deleted file mode 100644 index 231296f66e..0000000000 --- a/modules/angular2/src/core/annotations/view.ts +++ /dev/null @@ -1 +0,0 @@ -export {View as ViewAnnotation, ViewEncapsulation} from '../annotations_impl/view'; diff --git a/modules/angular2/src/core/application_common.ts b/modules/angular2/src/core/application_common.ts index 0e632c3b07..8bd5289198 100644 --- a/modules/angular2/src/core/application_common.ts +++ b/modules/angular2/src/core/application_common.ts @@ -359,12 +359,12 @@ export class ApplicationRef { } /** - * Returns the current {@link Component} type. + * Returns the current {@link ComponentMetadata} type. */ get hostComponentType(): Type { return this._hostComponentType; } /** - * Returns the current {@link Component} instance. + * Returns the current {@link ComponentMetadata} instance. */ get hostComponent(): any { return this._hostComponent.instance; } diff --git a/modules/angular2/src/core/compiler/compiler.ts b/modules/angular2/src/core/compiler/compiler.ts index 45e13164e6..4aee86ad9f 100644 --- a/modules/angular2/src/core/compiler/compiler.ts +++ b/modules/angular2/src/core/compiler/compiler.ts @@ -20,7 +20,7 @@ import {ProtoViewRef} from './view_ref'; import {DirectiveBinding} from './element_injector'; import {ViewResolver} from './view_resolver'; import {PipeResolver} from './pipe_resolver'; -import {View} from '../annotations_impl/view'; +import {ViewMetadata} from 'angular2/metadata'; import {ComponentUrlMapper} from './component_url_mapper'; import {ProtoViewFactory} from './proto_view_factory'; import {UrlResolver} from 'angular2/src/services/url_resolver'; @@ -30,7 +30,14 @@ import {wtfStartTimeRange, wtfEndTimeRange} from '../../profile/profile'; import {PipeBinding} from '../pipes/pipe_binding'; import {DEFAULT_PIPES_TOKEN} from 'angular2/pipes'; -import * as renderApi from 'angular2/src/render/api'; +import { + RenderDirectiveMetadata, + ViewDefinition, + RenderCompiler, + ViewType, + RenderProtoViewMergeMapping, + RenderProtoViewRef +} from 'angular2/src/render/api'; /** * Cache that stores the AppProtoView of the template of a component. @@ -97,8 +104,8 @@ export class Compiler { @Inject(DEFAULT_PIPES_TOKEN) _defaultPipes: Type[], private _compilerCache: CompilerCache, private _viewResolver: ViewResolver, private _componentUrlMapper: ComponentUrlMapper, private _urlResolver: UrlResolver, - private _render: renderApi.RenderCompiler, - private _protoViewFactory: ProtoViewFactory, appUrl: AppRootUrl) { + private _render: RenderCompiler, private _protoViewFactory: ProtoViewFactory, + appUrl: AppRootUrl) { this._defaultPipes = _defaultPipes; this._appUrl = appUrl.value; } @@ -215,7 +222,7 @@ export class Compiler { componentPath: Map): Promise { var nestedPVPromises = []; componentPath = MapWrapper.clone(componentPath); - if (appProtoViews[0].type === renderApi.ViewType.COMPONENT) { + if (appProtoViews[0].type === ViewType.COMPONENT) { componentPath.set(componentType, appProtoViews[0]); } appProtoViews.forEach(appProtoView => { @@ -230,7 +237,7 @@ export class Compiler { if (appProtoView.isEmbeddedFragment) { throw new BaseException( ` is used within the recursive path of ${stringify(nestedComponentType)}`); - } else if (appProtoView.type === renderApi.ViewType.COMPONENT) { + } else if (appProtoView.type === ViewType.COMPONENT) { throw new BaseException( `Unconditional component cycle in ${stringify(nestedComponentType)}`); } else { @@ -253,18 +260,17 @@ export class Compiler { } private _mergeProtoView(appProtoView: AppProtoView): Promise { - if (appProtoView.type !== renderApi.ViewType.HOST && - appProtoView.type !== renderApi.ViewType.EMBEDDED) { + if (appProtoView.type !== ViewType.HOST && appProtoView.type !== ViewType.EMBEDDED) { return null; } return this._render.mergeProtoViewsRecursively(this._collectMergeRenderProtoViews(appProtoView)) - .then((mergeResult: renderApi.RenderProtoViewMergeMapping) => { + .then((mergeResult: RenderProtoViewMergeMapping) => { appProtoView.mergeMapping = new AppProtoViewMergeMapping(mergeResult); }); } - private _collectMergeRenderProtoViews( - appProtoView: AppProtoView): List> { + private _collectMergeRenderProtoViews(appProtoView: + AppProtoView): List> { var result = [appProtoView.render]; for (var i = 0; i < appProtoView.elementBinders.length; i++) { var binder = appProtoView.elementBinders[i]; @@ -290,7 +296,7 @@ export class Compiler { return componentElementBinders; } - private _buildRenderTemplate(component, view, directives): renderApi.ViewDefinition { + private _buildRenderTemplate(component, view, directives): ViewDefinition { var componentUrl = this._urlResolver.resolve(this._appUrl, this._componentUrlMapper.getUrl(component)); var templateAbsUrl = null; @@ -307,7 +313,7 @@ export class Compiler { styleAbsUrls = ListWrapper.map(view.styleUrls, url => this._urlResolver.resolve(componentUrl, url)); } - return new renderApi.ViewDefinition({ + return new ViewDefinition({ componentId: stringify(component), templateAbsUrl: templateAbsUrl, template: view.template, styleAbsUrls: styleAbsUrls, @@ -317,14 +323,14 @@ export class Compiler { }); } - private _flattenPipes(view: View): any[] { + private _flattenPipes(view: ViewMetadata): any[] { if (isBlank(view.pipes)) return this._defaultPipes; var pipes = ListWrapper.clone(this._defaultPipes); this._flattenList(view.pipes, pipes); return pipes; } - private _flattenDirectives(view: View): List { + private _flattenDirectives(view: ViewMetadata): List { if (isBlank(view.directives)) return []; var directives = []; this._flattenList(view.directives, directives); @@ -347,7 +353,7 @@ export class Compiler { } private static _assertTypeIsComponent(directiveBinding: DirectiveBinding): void { - if (directiveBinding.metadata.type !== renderApi.DirectiveMetadata.COMPONENT_TYPE) { + if (directiveBinding.metadata.type !== RenderDirectiveMetadata.COMPONENT_TYPE) { throw new BaseException( `Could not load '${stringify(directiveBinding.key.token)}' because it is not a component.`); } diff --git a/modules/angular2/src/core/compiler/component_url_mapper.ts b/modules/angular2/src/core/compiler/component_url_mapper.ts index aa83f88c5d..9e94b54206 100644 --- a/modules/angular2/src/core/compiler/component_url_mapper.ts +++ b/modules/angular2/src/core/compiler/component_url_mapper.ts @@ -3,7 +3,7 @@ import {Type, isPresent} from 'angular2/src/facade/lang'; import {Map, MapWrapper} from 'angular2/src/facade/collection'; /** - * Resolve a `Type` from a {@link Component} into a URL. + * Resolve a `Type` from a {@link ComponentMetadata} into a URL. * * This interface can be overridden by the application developer to create custom behavior. * diff --git a/modules/angular2/src/core/compiler/directive_lifecycle_reflector.dart b/modules/angular2/src/core/compiler/directive_lifecycle_reflector.dart index 76e3ea61e3..f9b1a2b7a1 100644 --- a/modules/angular2/src/core/compiler/directive_lifecycle_reflector.dart +++ b/modules/angular2/src/core/compiler/directive_lifecycle_reflector.dart @@ -1,10 +1,10 @@ library angular2.src.core.compiler.directive_lifecycle_reflector; -import 'package:angular2/src/core/annotations_impl/annotations.dart'; +import 'package:angular2/src/core/metadata.dart'; import 'package:angular2/src/core/compiler/interfaces.dart'; import 'package:angular2/src/reflection/reflection.dart'; -bool hasLifecycleHook(LifecycleEvent e, type, Directive annotation) { +bool hasLifecycleHook(LifecycleEvent e, type, DirectiveMetadata annotation) { if (annotation.lifecycle != null) { return annotation.lifecycle.contains(e); } else { diff --git a/modules/angular2/src/core/compiler/directive_lifecycle_reflector.ts b/modules/angular2/src/core/compiler/directive_lifecycle_reflector.ts index c545f5040a..c34bc81160 100644 --- a/modules/angular2/src/core/compiler/directive_lifecycle_reflector.ts +++ b/modules/angular2/src/core/compiler/directive_lifecycle_reflector.ts @@ -1,7 +1,7 @@ import {Type, isPresent} from 'angular2/src/facade/lang'; -import {LifecycleEvent, Directive} from 'angular2/src/core/annotations_impl/annotations'; +import {LifecycleEvent, DirectiveMetadata} from 'angular2/metadata'; -export function hasLifecycleHook(e: LifecycleEvent, type, annotation: Directive): boolean { +export function hasLifecycleHook(e: LifecycleEvent, type, annotation: DirectiveMetadata): boolean { if (isPresent(annotation.lifecycle)) { return annotation.lifecycle.indexOf(e) !== -1; } else { diff --git a/modules/angular2/src/core/compiler/directive_resolver.ts b/modules/angular2/src/core/compiler/directive_resolver.ts index b8fb2ebdac..6f55c8c3b5 100644 --- a/modules/angular2/src/core/compiler/directive_resolver.ts +++ b/modules/angular2/src/core/compiler/directive_resolver.ts @@ -1,10 +1,10 @@ import {resolveForwardRef, Injectable} from 'angular2/di'; import {Type, isPresent, BaseException, stringify} from 'angular2/src/facade/lang'; -import {Directive} from '../annotations_impl/annotations'; +import {DirectiveMetadata} from 'angular2/metadata'; import {reflector} from 'angular2/src/reflection/reflection'; /** - * Resolve a `Type` for {@link Directive}. + * Resolve a `Type` for {@link DirectiveMetadata}. * * This interface can be overridden by the application developer to create custom behavior. * @@ -13,14 +13,14 @@ import {reflector} from 'angular2/src/reflection/reflection'; @Injectable() export class DirectiveResolver { /** - * Return {@link Directive} for a given `Type`. + * Return {@link DirectiveMetadata} for a given `Type`. */ - resolve(type: Type): Directive { + resolve(type: Type): DirectiveMetadata { var annotations = reflector.annotations(resolveForwardRef(type)); if (isPresent(annotations)) { for (var i = 0; i < annotations.length; i++) { var annotation = annotations[i]; - if (annotation instanceof Directive) { + if (annotation instanceof DirectiveMetadata) { return annotation; } } diff --git a/modules/angular2/src/core/compiler/element_injector.ts b/modules/angular2/src/core/compiler/element_injector.ts index 98b0682182..6982b980b2 100644 --- a/modules/angular2/src/core/compiler/element_injector.ts +++ b/modules/angular2/src/core/compiler/element_injector.ts @@ -31,19 +31,19 @@ import { BindingWithVisibility } from 'angular2/src/di/injector'; -import {Attribute, Query} from 'angular2/src/core/annotations_impl/di'; +import {AttributeMetadata, QueryMetadata} from '../metadata/di'; import * as viewModule from './view'; import * as avmModule from './view_manager'; import {ViewContainerRef} from './view_container_ref'; import {ElementRef} from './element_ref'; import {TemplateRef} from './template_ref'; -import {Directive, Component, LifecycleEvent} from 'angular2/src/core/annotations_impl/annotations'; +import {DirectiveMetadata, ComponentMetadata, LifecycleEvent} from '../metadata/directives'; import {hasLifecycleHook} from './directive_lifecycle_reflector'; import {ChangeDetector, ChangeDetectorRef} from 'angular2/src/change_detection/change_detection'; import {QueryList} from './query_list'; import {reflector} from 'angular2/src/reflection/reflection'; -import {DirectiveMetadata} from 'angular2/src/render/api'; +import {RenderDirectiveMetadata} from 'angular2/src/render/api'; import {PipeBinding} from '../pipes/pipe_binding'; var _staticKeys; @@ -160,7 +160,7 @@ export class TreeNode> { export class DirectiveDependency extends Dependency { constructor(key: Key, optional: boolean, lowerBoundVisibility: Object, upperBoundVisibility: Object, properties: List, public attributeName: string, - public queryDecorator: Query) { + public queryDecorator: QueryMetadata) { super(key, optional, lowerBoundVisibility, upperBoundVisibility, properties); this._verify(); } @@ -181,12 +181,12 @@ export class DirectiveDependency extends Dependency { } static _attributeName(properties): string { - var p = ListWrapper.find(properties, (p) => p instanceof Attribute); + var p = ListWrapper.find(properties, (p) => p instanceof AttributeMetadata); return isPresent(p) ? p.attributeName : null; } - static _query(properties): Query { - return ListWrapper.find(properties, (p) => p instanceof Query); + static _query(properties): QueryMetadata { + return ListWrapper.find(properties, (p) => p instanceof QueryMetadata); } } @@ -194,7 +194,7 @@ export class DirectiveBinding extends ResolvedBinding { constructor(key: Key, factory: Function, dependencies: List, public resolvedBindings: List, public resolvedViewBindings: List, - public metadata: DirectiveMetadata) { + public metadata: RenderDirectiveMetadata) { super(key, factory, dependencies); } @@ -218,21 +218,21 @@ export class DirectiveBinding extends ResolvedBinding { get changeDetection() { return this.metadata.changeDetection; } - static createFromBinding(binding: Binding, ann: Directive): DirectiveBinding { + static createFromBinding(binding: Binding, ann: DirectiveMetadata): DirectiveBinding { if (isBlank(ann)) { - ann = new Directive(); + ann = new DirectiveMetadata(); } var rb = binding.resolve(); var deps = ListWrapper.map(rb.dependencies, DirectiveDependency.createFrom); var resolvedBindings = isPresent(ann.bindings) ? Injector.resolve(ann.bindings) : []; - var resolvedViewBindings = ann instanceof Component && isPresent(ann.viewBindings) ? + var resolvedViewBindings = ann instanceof ComponentMetadata && isPresent(ann.viewBindings) ? Injector.resolve(ann.viewBindings) : []; - var metadata = DirectiveMetadata.create({ + var metadata = RenderDirectiveMetadata.create({ id: stringify(rb.key.token), - type: ann instanceof Component ? DirectiveMetadata.COMPONENT_TYPE : - DirectiveMetadata.DIRECTIVE_TYPE, + type: ann instanceof ComponentMetadata ? RenderDirectiveMetadata.COMPONENT_TYPE : + RenderDirectiveMetadata.DIRECTIVE_TYPE, selector: ann.selector, compileChildren: ann.compileChildren, events: ann.events, @@ -246,7 +246,7 @@ export class DirectiveBinding extends ResolvedBinding { callOnInit: hasLifecycleHook(LifecycleEvent.onInit, rb.key.token, ann), callOnAllChangesDone: hasLifecycleHook(LifecycleEvent.onAllChangesDone, rb.key.token, ann), - changeDetection: ann instanceof Component ? ann.changeDetection : null, + changeDetection: ann instanceof ComponentMetadata ? ann.changeDetection : null, exportAs: ann.exportAs }); @@ -264,7 +264,7 @@ export class DirectiveBinding extends ResolvedBinding { return readAttributes; } - static createFromType(type: Type, annotation: Directive): DirectiveBinding { + static createFromType(type: Type, annotation: DirectiveMetadata): DirectiveBinding { var binding = new Binding(type, {toClass: type}); return DirectiveBinding.createFromBinding(binding, annotation); } @@ -608,7 +608,7 @@ export class ElementInjector extends TreeNode implements Depend if (dirDep.key.id === StaticKeys.instance().changeDetectorRefId) { // We provide the component's view change detector to components and // the surrounding component's change detector to directives. - if (dirBin.metadata.type === DirectiveMetadata.COMPONENT_TYPE) { + if (dirBin.metadata.type === RenderDirectiveMetadata.COMPONENT_TYPE) { var componentView = this._preBuiltObjects.view.getNestedView( this._preBuiltObjects.elementRef.boundElementIndex); return componentView.changeDetector.ref; @@ -713,7 +713,7 @@ export class ElementInjector extends TreeNode implements Depend matched.forEach(s => queryRef.list.add(s)); } - private _createQueryRef(query: Query): void { + private _createQueryRef(query: QueryMetadata): void { var queryList = new QueryList(); if (isBlank(this._query0)) { this._query0 = new QueryRef(query, queryList, this); @@ -726,7 +726,7 @@ export class ElementInjector extends TreeNode implements Depend } } - addDirectivesMatchingQuery(query: Query, list: any[]): void { + addDirectivesMatchingQuery(query: QueryMetadata, list: any[]): void { var templateRef = this._preBuiltObjects.templateRef; if (query.selector === TemplateRef && isPresent(templateRef)) { list.push(templateRef); @@ -873,7 +873,7 @@ interface _ElementInjectorStrategy { getComponent(): any; isComponentKey(key: Key): boolean; buildQueries(): void; - addDirectivesMatchingQuery(q: Query, res: any[]): void; + addDirectivesMatchingQuery(q: QueryMetadata, res: any[]): void; getComponentBinding(): DirectiveBinding; hydrate(): void; dehydrate(): void; @@ -1006,7 +1006,7 @@ class ElementInjectorInlineStrategy implements _ElementInjectorStrategy { } } - addDirectivesMatchingQuery(query: Query, list: any[]): void { + addDirectivesMatchingQuery(query: QueryMetadata, list: any[]): void { var i = this.injectorStrategy; var p = i.protoStrategy; @@ -1112,7 +1112,7 @@ class ElementInjectorDynamicStrategy implements _ElementInjectorStrategy { } } - addDirectivesMatchingQuery(query: Query, list: any[]): void { + addDirectivesMatchingQuery(query: QueryMetadata, list: any[]): void { var ist = this.injectorStrategy; var p = ist.protoStrategy; @@ -1144,7 +1144,7 @@ export class QueryError extends BaseException { } export class QueryRef { - constructor(public query: Query, public list: QueryList, + constructor(public query: QueryMetadata, public list: QueryList, public originator: ElementInjector) {} get isViewQuery(): boolean { return this.query.isViewQuery; } diff --git a/modules/angular2/src/core/compiler/pipe_resolver.ts b/modules/angular2/src/core/compiler/pipe_resolver.ts index a18923bb64..2ecc61a844 100644 --- a/modules/angular2/src/core/compiler/pipe_resolver.ts +++ b/modules/angular2/src/core/compiler/pipe_resolver.ts @@ -1,10 +1,10 @@ import {resolveForwardRef, Injectable} from 'angular2/di'; import {Type, isPresent, BaseException, stringify} from 'angular2/src/facade/lang'; -import {Pipe} from '../annotations_impl/annotations'; +import {PipeMetadata} from '../metadata/directives'; import {reflector} from 'angular2/src/reflection/reflection'; /** - * Resolve a `Type` for {@link Pipe}. + * Resolve a `Type` for {@link PipeMetadata}. * * This interface can be overridden by the application developer to create custom behavior. * @@ -13,14 +13,14 @@ import {reflector} from 'angular2/src/reflection/reflection'; @Injectable() export class PipeResolver { /** - * Return {@link Pipe} for a given `Type`. + * Return {@link PipeMetadata} for a given `Type`. */ - resolve(type: Type): Pipe { + resolve(type: Type): PipeMetadata { var metas = reflector.annotations(resolveForwardRef(type)); if (isPresent(metas)) { for (var i = 0; i < metas.length; i++) { var annotation = metas[i]; - if (annotation instanceof Pipe) { + if (annotation instanceof PipeMetadata) { return annotation; } } diff --git a/modules/angular2/src/core/compiler/proto_view_factory.ts b/modules/angular2/src/core/compiler/proto_view_factory.ts index d31c076cbf..fef99ed9ee 100644 --- a/modules/angular2/src/core/compiler/proto_view_factory.ts +++ b/modules/angular2/src/core/compiler/proto_view_factory.ts @@ -18,7 +18,14 @@ import { import {PipeBinding} from 'angular2/src/core/pipes/pipe_binding'; import {ProtoPipes} from 'angular2/src/core/pipes/pipes'; -import * as renderApi from 'angular2/src/render/api'; +import { + RenderDirectiveMetadata, + RenderElementBinder, + PropertyBindingType, + DirectiveBinder, + ProtoViewDto, + ViewType +} from 'angular2/src/render/api'; import {AppProtoView} from './view'; import {ElementBinder} from './element_binder'; import {ProtoElementInjector, DirectiveBinding} from './element_injector'; @@ -26,8 +33,8 @@ import {ProtoElementInjector, DirectiveBinding} from './element_injector'; export class BindingRecordsCreator { _directiveRecordsMap: Map = new Map(); - getEventBindingRecords(elementBinders: List, - allDirectiveMetadatas: renderApi.DirectiveMetadata[]): BindingRecord[] { + getEventBindingRecords(elementBinders: List, + allDirectiveMetadatas: RenderDirectiveMetadata[]): BindingRecord[] { var res = []; for (var boundElementIndex = 0; boundElementIndex < elementBinders.length; boundElementIndex++) { @@ -41,16 +48,15 @@ export class BindingRecordsCreator { } private _createTemplateEventRecords(res: BindingRecord[], - renderElementBinder: renderApi.ElementBinder, + renderElementBinder: RenderElementBinder, boundElementIndex: number): void { renderElementBinder.eventBindings.forEach(eb => { res.push(BindingRecord.createForEvent(eb.source, eb.fullName, boundElementIndex)); }); } - private _createHostEventRecords(res: BindingRecord[], - renderElementBinder: renderApi.ElementBinder, - allDirectiveMetadatas: renderApi.DirectiveMetadata[], + private _createHostEventRecords(res: BindingRecord[], renderElementBinder: RenderElementBinder, + allDirectiveMetadatas: RenderDirectiveMetadata[], boundElementIndex: number): void { for (var i = 0; i < renderElementBinder.directives.length; ++i) { var dir = renderElementBinder.directives[i]; @@ -63,9 +69,9 @@ export class BindingRecordsCreator { } getPropertyBindingRecords(textBindings: List, - elementBinders: List, + elementBinders: List, allDirectiveMetadatas: - List): List { + List): List { var bindings = []; this._createTextNodeRecords(bindings, textBindings); @@ -80,9 +86,8 @@ export class BindingRecordsCreator { return bindings; } - getDirectiveRecords(elementBinders: List, - allDirectiveMetadatas: - List): List { + getDirectiveRecords(elementBinders: List, + allDirectiveMetadatas: List): List { var directiveRecords = []; for (var elementIndex = 0; elementIndex < elementBinders.length; ++elementIndex) { @@ -103,18 +108,18 @@ export class BindingRecordsCreator { } _createElementPropertyRecords(bindings: List, boundElementIndex: number, - renderElementBinder: renderApi.ElementBinder) { + renderElementBinder: RenderElementBinder) { ListWrapper.forEach(renderElementBinder.propertyBindings, (binding) => { - if (binding.type === renderApi.PropertyBindingType.PROPERTY) { + if (binding.type === PropertyBindingType.PROPERTY) { bindings.push(BindingRecord.createForElementProperty(binding.astWithSource, boundElementIndex, binding.property)); - } else if (binding.type === renderApi.PropertyBindingType.ATTRIBUTE) { + } else if (binding.type === PropertyBindingType.ATTRIBUTE) { bindings.push(BindingRecord.createForElementAttribute(binding.astWithSource, boundElementIndex, binding.property)); - } else if (binding.type === renderApi.PropertyBindingType.CLASS) { + } else if (binding.type === PropertyBindingType.CLASS) { bindings.push(BindingRecord.createForElementClass(binding.astWithSource, boundElementIndex, binding.property)); - } else if (binding.type === renderApi.PropertyBindingType.STYLE) { + } else if (binding.type === PropertyBindingType.STYLE) { bindings.push(BindingRecord.createForElementStyle(binding.astWithSource, boundElementIndex, binding.property, binding.unit)); } @@ -122,8 +127,8 @@ export class BindingRecordsCreator { } _createDirectiveRecords(bindings: List, boundElementIndex: number, - directiveBinders: List, - allDirectiveMetadatas: List) { + directiveBinders: List, + allDirectiveMetadatas: List) { for (var i = 0; i < directiveBinders.length; i++) { var directiveBinder = directiveBinders[i]; var directiveMetadata = allDirectiveMetadatas[directiveBinder.directiveIndex]; @@ -154,16 +159,16 @@ export class BindingRecordsCreator { // host properties ListWrapper.forEach(directiveBinder.hostPropertyBindings, (binding) => { var dirIndex = new DirectiveIndex(boundElementIndex, i); - if (binding.type === renderApi.PropertyBindingType.PROPERTY) { + if (binding.type === PropertyBindingType.PROPERTY) { bindings.push(BindingRecord.createForHostProperty(dirIndex, binding.astWithSource, binding.property)); - } else if (binding.type === renderApi.PropertyBindingType.ATTRIBUTE) { + } else if (binding.type === PropertyBindingType.ATTRIBUTE) { bindings.push(BindingRecord.createForHostAttribute(dirIndex, binding.astWithSource, binding.property)); - } else if (binding.type === renderApi.PropertyBindingType.CLASS) { + } else if (binding.type === PropertyBindingType.CLASS) { bindings.push( BindingRecord.createForHostClass(dirIndex, binding.astWithSource, binding.property)); - } else if (binding.type === renderApi.PropertyBindingType.STYLE) { + } else if (binding.type === PropertyBindingType.STYLE) { bindings.push(BindingRecord.createForHostStyle(dirIndex, binding.astWithSource, binding.property, binding.unit)); } @@ -172,7 +177,7 @@ export class BindingRecordsCreator { } _getDirectiveRecord(boundElementIndex: number, directiveIndex: number, - directiveMetadata: renderApi.DirectiveMetadata): DirectiveRecord { + directiveMetadata: RenderDirectiveMetadata): DirectiveRecord { var id = boundElementIndex * 100 + directiveIndex; if (!this._directiveRecordsMap.has(id)) { @@ -198,8 +203,7 @@ export class ProtoViewFactory { */ constructor(public _changeDetection: ChangeDetection) {} - createAppProtoViews(hostComponentBinding: DirectiveBinding, - rootRenderProtoView: renderApi.ProtoViewDto, + createAppProtoViews(hostComponentBinding: DirectiveBinding, rootRenderProtoView: ProtoViewDto, allDirectives: List, pipes: PipeBinding[]): AppProtoView[] { var allRenderDirectiveMetadata = ListWrapper.map(allDirectives, directiveBinding => directiveBinding.metadata); @@ -233,8 +237,8 @@ export class ProtoViewFactory { * for the given ProtoView and all nested ProtoViews. */ export function getChangeDetectorDefinitions( - hostComponentMetadata: renderApi.DirectiveMetadata, rootRenderProtoView: renderApi.ProtoViewDto, - allRenderDirectiveMetadata: List): List { + hostComponentMetadata: RenderDirectiveMetadata, rootRenderProtoView: ProtoViewDto, + allRenderDirectiveMetadata: List): List { var nestedPvsWithIndex = _collectNestedProtoViews(rootRenderProtoView); var nestedPvVariableNames = _collectNestedProtoViewsVariableNames(nestedPvsWithIndex); return _getChangeDetectorDefinitions(hostComponentMetadata, nestedPvsWithIndex, @@ -242,7 +246,7 @@ export function getChangeDetectorDefinitions( } function _collectNestedProtoViews( - renderProtoView: renderApi.ProtoViewDto, parentIndex: number = null, boundElementIndex = null, + renderProtoView: ProtoViewDto, parentIndex: number = null, boundElementIndex = null, result: List = null): List { if (isBlank(result)) { result = []; @@ -263,9 +267,9 @@ function _collectNestedProtoViews( } function _getChangeDetectorDefinitions( - hostComponentMetadata: renderApi.DirectiveMetadata, + hostComponentMetadata: RenderDirectiveMetadata, nestedPvsWithIndex: List, nestedPvVariableNames: List>, - allRenderDirectiveMetadata: List): List { + allRenderDirectiveMetadata: List): List { return ListWrapper.map(nestedPvsWithIndex, (pvWithIndex) => { var elementBinders = pvWithIndex.renderProtoView.elementBinders; var bindingRecordsCreator = new BindingRecordsCreator(); @@ -277,10 +281,10 @@ function _getChangeDetectorDefinitions( bindingRecordsCreator.getDirectiveRecords(elementBinders, allRenderDirectiveMetadata); var strategyName = DEFAULT; var typeString; - if (pvWithIndex.renderProtoView.type === renderApi.ViewType.COMPONENT) { + if (pvWithIndex.renderProtoView.type === ViewType.COMPONENT) { strategyName = hostComponentMetadata.changeDetection; typeString = 'comp'; - } else if (pvWithIndex.renderProtoView.type === renderApi.ViewType.HOST) { + } else if (pvWithIndex.renderProtoView.type === ViewType.HOST) { typeString = 'host'; } else { typeString = 'embedded'; @@ -293,7 +297,7 @@ function _getChangeDetectorDefinitions( } function _createAppProtoView( - renderProtoView: renderApi.ProtoViewDto, protoChangeDetector: ProtoChangeDetector, + renderProtoView: ProtoViewDto, protoChangeDetector: ProtoChangeDetector, variableBindings: Map, allDirectives: List, pipes: PipeBinding[]): AppProtoView { var elementBinders = renderProtoView.elementBinders; @@ -346,7 +350,7 @@ function _createVariableNames(parentVariableNames: List, renderProtoView return res; } -export function createVariableLocations(elementBinders: List): +export function createVariableLocations(elementBinders: List): Map { var variableLocations = new Map(); for (var i = 0; i < elementBinders.length; i++) { @@ -368,7 +372,7 @@ function _createElementBinders(protoView, elementBinders, allDirectiveBindings) ListWrapper.map(dirs, (dir) => allDirectiveBindings[dir.directiveIndex]); var componentDirectiveBinding = null; if (directiveBindings.length > 0) { - if (directiveBindings[0].metadata.type === renderApi.DirectiveMetadata.COMPONENT_TYPE) { + if (directiveBindings[0].metadata.type === RenderDirectiveMetadata.COMPONENT_TYPE) { componentDirectiveBinding = directiveBindings[0]; } } @@ -439,7 +443,7 @@ function _createElementBinder(protoView: AppProtoView, boundElementIndex, render return elBinder; } -export function createDirectiveVariableBindings(renderElementBinder: renderApi.ElementBinder, +export function createDirectiveVariableBindings(renderElementBinder: RenderElementBinder, directiveBindings: List): Map { var directiveVariableBindings = new Map(); @@ -478,7 +482,7 @@ function _findDirectiveIndexByExportAs(renderElementBinder, directiveBindings, e function _directiveExportAs(directive): string { var directiveExportAs = directive.metadata.exportAs; if (isBlank(directiveExportAs) && - directive.metadata.type === renderApi.DirectiveMetadata.COMPONENT_TYPE) { + directive.metadata.type === RenderDirectiveMetadata.COMPONENT_TYPE) { return "$implicit"; } else { return directiveExportAs; @@ -486,7 +490,7 @@ function _directiveExportAs(directive): string { } class RenderProtoViewWithIndex { - constructor(public renderProtoView: renderApi.ProtoViewDto, public index: number, + constructor(public renderProtoView: ProtoViewDto, public index: number, public parentIndex: number, public boundElementIndex: number) {} } diff --git a/modules/angular2/src/core/compiler/view_resolver.ts b/modules/angular2/src/core/compiler/view_resolver.ts index fe85096698..89d0b6de1c 100644 --- a/modules/angular2/src/core/compiler/view_resolver.ts +++ b/modules/angular2/src/core/compiler/view_resolver.ts @@ -1,5 +1,5 @@ import {Injectable} from 'angular2/di'; -import {View} from 'angular2/src/core/annotations_impl/view'; +import {ViewMetadata} from '../metadata/view'; import {Type, stringify, isBlank, BaseException} from 'angular2/src/facade/lang'; import {Map, MapWrapper, List, ListWrapper} from 'angular2/src/facade/collection'; @@ -11,7 +11,7 @@ import {reflector} from 'angular2/src/reflection/reflection'; export class ViewResolver { _cache: Map = new Map(); - resolve(component: Type): View { + resolve(component: Type): ViewMetadata { var view = this._cache.get(component); if (isBlank(view)) { @@ -22,11 +22,11 @@ export class ViewResolver { return view; } - _resolve(component: Type): View { + _resolve(component: Type): ViewMetadata { var annotations = reflector.annotations(component); for (var i = 0; i < annotations.length; i++) { var annotation = annotations[i]; - if (annotation instanceof View) { + if (annotation instanceof ViewMetadata) { return annotation; } } diff --git a/modules/angular2/src/core/metadata.dart b/modules/angular2/src/core/metadata.dart new file mode 100644 index 0000000000..f968a71708 --- /dev/null +++ b/modules/angular2/src/core/metadata.dart @@ -0,0 +1,97 @@ +library angular2.src.core.metadata; + +import "package:angular2/src/facade/collection.dart" show List; +import "./metadata/di.dart"; +import "./metadata/directives.dart"; +import "./metadata/view.dart"; + +export "./metadata/di.dart"; +export "./metadata/directives.dart"; +export "./metadata/view.dart"; + +/** + * See: [DirectiveMetadata] for docs. + */ +class Directive extends DirectiveMetadata { + const Directive({String selector, List properties, + List events, Map host, + List lifecycle, List bindings, String exportAs, + bool compileChildren: true}) + : super( + selector: selector, + properties: properties, + events: events, + host: host, + lifecycle: lifecycle, + bindings: bindings, + exportAs: exportAs, + compileChildren: compileChildren); +} + +/** + * See: [ComponentMetadata] for docs. + */ +class Component extends ComponentMetadata { + const Component({String selector, List properties, + List events, Map host, + List lifecycle, List bindings, String exportAs, + bool compileChildren, List viewBindings, String changeDetection}) + : super( + selector: selector, + properties: properties, + events: events, + host: host, + lifecycle: lifecycle, + bindings: bindings, + exportAs: exportAs, + compileChildren: compileChildren, + viewBindings: viewBindings, + changeDetection: changeDetection); +} + +/** + * See: [ViewMetadata] for docs. + */ +class View extends ViewMetadata { + const View({String templateUrl, String template, dynamic directives, + dynamic pipes, ViewEncapsulation encapsulation, List styles, + List styleUrls}) + : super( + templateUrl: templateUrl, + template: template, + directives: directives, + pipes: pipes, + encapsulation: encapsulation, + styles: styles, + styleUrls: styleUrls); +} + +/** + * See: [PipeMetadata] for docs. + */ +class Pipe extends PipeMetadata { + const Pipe({name}) : super(name: name); +} + +/** + * See: [AttributeMetadata] for docs. + */ +class Attribute extends AttributeMetadata { + const Attribute(String attributeName) : super(attributeName); +} + +/** + * See: [QueryMetadata] for docs. + */ +class Query extends QueryMetadata { + const Query(dynamic /*Type | string*/ selector, {bool descendants: false}) + : super(selector, descendants: descendants); +} + +/** + * See: [ViewQueryMetadata] for docs. + */ +class ViewQuery extends ViewQueryMetadata { + const ViewQuery(dynamic /*Type | string*/ selector, {bool descendants: false}) + : super(selector, descendants: descendants); +} diff --git a/modules/angular2/src/core/annotations/decorators.ts b/modules/angular2/src/core/metadata.ts similarity index 76% rename from modules/angular2/src/core/annotations/decorators.ts rename to modules/angular2/src/core/metadata.ts index c1c40a89dc..f7c2513640 100644 --- a/modules/angular2/src/core/annotations/decorators.ts +++ b/modules/angular2/src/core/metadata.ts @@ -1,30 +1,57 @@ -import { - ComponentAnnotation, - DirectiveAnnotation, - PipeAnnotation, +/** + * This indirection is needed to free up Component, etc symbols in the public API + * to be used by the decorator versions of these annotations. + */ + +export { + QueryMetadata, + ViewQueryMetadata, + AttributeMetadata, +} from './metadata/di'; + +export { + ComponentMetadata, + DirectiveMetadata, + PipeMetadata, LifecycleEvent -} from './annotations'; -import {ViewAnnotation} from './view'; -import {AttributeAnnotation, QueryAnnotation, ViewQueryAnnotation} from './di'; -import {makeDecorator, makeParamDecorator, TypeDecorator, Class} from '../../util/decorators'; +} from './metadata/directives'; + +export {ViewMetadata, ViewEncapsulation} from './metadata/view'; + + +import { + QueryMetadata, + ViewQueryMetadata, + AttributeMetadata, +} from './metadata/di'; + +import { + ComponentMetadata, + DirectiveMetadata, + PipeMetadata, + LifecycleEvent +} from './metadata/directives'; + +import {ViewMetadata, ViewEncapsulation} from './metadata/view'; + +import {makeDecorator, makeParamDecorator, TypeDecorator, Class} from '../util/decorators'; import {Type} from 'angular2/src/facade/lang'; -import {ViewEncapsulation} from 'angular2/src/render/api'; /** - * Interface for the {@link Directive} decorator function. + * Interface for the {@link DirectiveMetadata} decorator function. * * See {@link DirectiveFactory}. */ export interface DirectiveDecorator extends TypeDecorator {} /** - * Interface for the {@link Component} decorator function. + * Interface for the {@link ComponentMetadata} decorator function. * * See {@link ComponentFactory}. */ export interface ComponentDecorator extends TypeDecorator { /** - * Chain {@link View} annotation. + * Chain {@link ViewMetadata} annotation. */ View(obj: { templateUrl?: string, @@ -38,13 +65,13 @@ export interface ComponentDecorator extends TypeDecorator { } /** - * Interface for the {@link View} decorator function. + * Interface for the {@link ViewMetadata} decorator function. * * See {@link ViewFactory}. */ export interface ViewDecorator extends TypeDecorator { /** - * Chain {@link View} annotation. + * Chain {@link ViewMetadata} annotation. */ View(obj: { templateUrl?: string, @@ -58,7 +85,7 @@ export interface ViewDecorator extends TypeDecorator { } /** - * {@link Directive} factory for creating annotations, decorators or DSL. + * {@link DirectiveMetadata} factory for creating annotations, decorators or DSL. * * ## Example as TypeScript Decorator * @@ -107,7 +134,7 @@ export interface DirectiveFactory { selector?: string, properties?: List, events?: List, host?: StringMap, lifecycle?: List, bindings?: List, exportAs?: string, compileChildren?: boolean; - }): DirectiveAnnotation; + }): DirectiveMetadata; } /** @@ -177,7 +204,7 @@ export interface ComponentFactory { compileChildren?: boolean, viewBindings?: List, changeDetection?: string, - }): ComponentAnnotation; + }): ComponentMetadata; } /** @@ -239,11 +266,11 @@ export interface ViewFactory { encapsulation?: ViewEncapsulation, styles?: List, styleUrls?: List, - }): ViewAnnotation; + }): ViewMetadata; } /** - * {@link Attribute} factory for creating annotations, decorators or DSL. + * {@link AttributeMetadata} factory for creating annotations, decorators or DSL. * * ## Example as TypeScript Decorator * @@ -290,11 +317,11 @@ export interface ViewFactory { */ export interface AttributeFactory { (name: string): TypeDecorator; - new (name: string): AttributeAnnotation; + new (name: string): AttributeMetadata; } /** - * {@link Query} factory for creating annotations, decorators or DSL. + * {@link QueryMetadata} factory for creating annotations, decorators or DSL. * * ## Example as TypeScript Decorator * @@ -341,11 +368,11 @@ export interface AttributeFactory { */ export interface QueryFactory { (selector: Type | string, {descendants}?: {descendants?: boolean}): ParameterDecorator; - new (selector: Type | string, {descendants}?: {descendants?: boolean}): QueryAnnotation; + new (selector: Type | string, {descendants}?: {descendants?: boolean}): QueryMetadata; } /** - * {@link Pipe} factory for creating decorators. + * {@link PipeMetadata} factory for creating decorators. * * ## Example as TypeScript Decorator * @@ -370,38 +397,38 @@ export interface PipeFactory { } /** - * {@link Component} factory function. + * {@link ComponentMetadata} factory function. */ export var Component: ComponentFactory = - makeDecorator(ComponentAnnotation, (fn: any) => fn.View = View); + makeDecorator(ComponentMetadata, (fn: any) => fn.View = View); /** - * {@link Directive} factory function. + * {@link DirectiveMetadata} factory function. */ -export var Directive: DirectiveFactory = makeDecorator(DirectiveAnnotation); +export var Directive: DirectiveFactory = makeDecorator(DirectiveMetadata); /** - * {@link View} factory function. + * {@link ViewMetadata} factory function. */ export var View: ViewFactory = - makeDecorator(ViewAnnotation, (fn: any) => fn.View = View); + makeDecorator(ViewMetadata, (fn: any) => fn.View = View); /** - * {@link Attribute} factory function. + * {@link AttributeMetadata} factory function. */ -export var Attribute: AttributeFactory = makeParamDecorator(AttributeAnnotation); +export var Attribute: AttributeFactory = makeParamDecorator(AttributeMetadata); /** - * {@link Query} factory function. + * {@link QueryMetadata} factory function. */ -export var Query: QueryFactory = makeParamDecorator(QueryAnnotation); +export var Query: QueryFactory = makeParamDecorator(QueryMetadata); /** - * {@link ViewQuery} factory function. + * {@link ViewQueryMetadata} factory function. */ -export var ViewQuery: QueryFactory = makeParamDecorator(ViewQueryAnnotation); +export var ViewQuery: QueryFactory = makeParamDecorator(ViewQueryMetadata); /** - * {@link Pipe} factory function. + * {@link PipeMetadata} factory function. */ -export var Pipe: PipeFactory = makeDecorator(PipeAnnotation); +export var Pipe: PipeFactory = makeDecorator(PipeMetadata); diff --git a/modules/angular2/src/core/annotations_impl/di.ts b/modules/angular2/src/core/metadata/di.ts similarity index 93% rename from modules/angular2/src/core/annotations_impl/di.ts rename to modules/angular2/src/core/metadata/di.ts index 1221be9ae4..e0b5ff0849 100644 --- a/modules/angular2/src/core/annotations_impl/di.ts +++ b/modules/angular2/src/core/metadata/di.ts @@ -29,7 +29,7 @@ import {resolveForwardRef} from 'angular2/di'; * ``` */ @CONST() -export class Attribute extends DependencyMetadata { +export class AttributeMetadata extends DependencyMetadata { constructor(public attributeName: string) { super(); } get token() { @@ -49,7 +49,7 @@ export class Attribute extends DependencyMetadata { * See {@link QueryList} for usage and example. */ @CONST() -export class Query extends DependencyMetadata { +export class QueryMetadata extends DependencyMetadata { descendants: boolean; constructor(private _selector: Type | string, {descendants = false}: {descendants?: boolean} = {}) { @@ -74,7 +74,7 @@ export class Query extends DependencyMetadata { * See {@link QueryList} for usage and example. */ @CONST() -export class ViewQuery extends Query { +export class ViewQueryMetadata extends QueryMetadata { constructor(_selector: Type | string, {descendants = false}: {descendants?: boolean} = {}) { super(_selector, {descendants: descendants}); } diff --git a/modules/angular2/src/core/annotations_impl/annotations.ts b/modules/angular2/src/core/metadata/directives.ts similarity index 97% rename from modules/angular2/src/core/annotations_impl/annotations.ts rename to modules/angular2/src/core/metadata/directives.ts index 85b17e381b..4e36f42dff 100644 --- a/modules/angular2/src/core/annotations_impl/annotations.ts +++ b/modules/angular2/src/core/metadata/directives.ts @@ -6,7 +6,7 @@ import {DEFAULT} from 'angular2/change_detection'; /** * Directives allow you to attach behavior to elements in the DOM. * - * {@link Directive}s with an embedded view are called {@link Component}s. + * {@link DirectiveMetadata}s with an embedded view are called {@link ComponentMetadata}s. * * A directive consists of a single directive annotation and a controller class. When the * directive's `selector` matches @@ -39,7 +39,7 @@ import {DEFAULT} from 'angular2/change_detection'; * current `ElementInjector` resolves the constructor dependencies for each directive. * * Angular then resolves dependencies as follows, according to the order in which they appear in the - * {@link View}: + * {@link ViewMetadata}: * * 1. Dependencies on the current element * 2. Dependencies on element injectors and their parents until it encounters a Shadow DOM boundary @@ -64,7 +64,7 @@ import {DEFAULT} from 'angular2/change_detection'; * To inject element-specific special objects, declare the constructor parameter as: * - `element: ElementRef` to obtain a reference to logical element in the view. * - `viewContainer: ViewContainerRef` to control child template instantiation, for - * {@link Directive} directives only + * {@link DirectiveMetadata} directives only * - `bindingPropagation: BindingPropagation` to control change detection in a more granular way. * * ## Example @@ -288,7 +288,7 @@ import {DEFAULT} from 'angular2/change_detection'; * location in the current view * where these actions are performed. * - * Views are always created as children of the current {@link View}, and as siblings of the + * Views are always created as children of the current {@link ViewMetadata}, and as siblings of the * `