From 00e2d70f05bbf7be87d84d56e074fb38d55539d6 Mon Sep 17 00:00:00 2001 From: Tim Blasi Date: Fri, 17 Apr 2015 15:07:31 -0700 Subject: [PATCH] refactor(dart/transform): Remove index_static from hello_world index_static.js & index_static.html are unnecessary in Js and are now essentially generated via the Dart transformer. The angular transformer is specified in examples/pubspec.yaml; use pub build to create a transformed application that does not use dart:mirrors. Create index_dynamic.js & index_dynamic.html, which are used to test that the app runs equally well with mirrors and without. Closes #495 --- gulpfile.js | 18 -- .../e2e_test/hello_world/hello_world_spec.es6 | 4 +- modules/examples/src/hello_world/index.html | 2 +- modules/examples/src/hello_world/index.js | 26 +- .../examples/src/hello_world/index_common.js | 15 +- .../{index_static.html => index_dynamic.html} | 2 +- .../examples/src/hello_world/index_dynamic.js | 11 + .../examples/src/hello_world/index_static.js | 306 ------------------ 8 files changed, 35 insertions(+), 349 deletions(-) rename modules/examples/src/hello_world/{index_static.html => index_dynamic.html} (68%) create mode 100644 modules/examples/src/hello_world/index_dynamic.js delete mode 100644 modules/examples/src/hello_world/index_static.js diff --git a/gulpfile.js b/gulpfile.js index 1d987656e7..a10617f15c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -355,24 +355,6 @@ gulp.task('serve/benchmarks_external.dart', pubserve(gulp, gulpPlugins, { path: CONFIG.dest.dart + '/benchmarks_external' })); -gulp.task('serve/examples.dart.static', pubserve(gulp, gulpPlugins, { - command: DART_SDK.PUB, - mode: 'ngstatic', - path: CONFIG.dest.dart + '/examples' -})); - -gulp.task('serve/benchmarks.dart.static', pubserve(gulp, gulpPlugins, { - command: DART_SDK.PUB, - mode: 'ngstatic', - path: CONFIG.dest.dart + '/benchmarks' -})); - -gulp.task('serve/benchmarks_external.dart.static', pubserve(gulp, gulpPlugins, { - command: DART_SDK.PUB, - mode: 'ngstatic', - path: CONFIG.dest.dart + '/benchmarks_external' -})); - // -------------- // doc generation var Dgeni = require('dgeni'); diff --git a/modules/examples/e2e_test/hello_world/hello_world_spec.es6 b/modules/examples/e2e_test/hello_world/hello_world_spec.es6 index a5f8c8bbf3..93a8c98103 100644 --- a/modules/examples/e2e_test/hello_world/hello_world_spec.es6 +++ b/modules/examples/e2e_test/hello_world/hello_world_spec.es6 @@ -4,7 +4,7 @@ describe('hello world', function () { afterEach(testUtil.verifyNoBrowserErrors); describe('static reflection', function() { - var URL = 'examples/src/hello_world/index_static.html'; + var URL = 'examples/src/hello_world/index.html'; it('should greet', function() { browser.get(URL); @@ -21,7 +21,7 @@ describe('hello world', function () { }); describe('dynamic reflection', function() { - var URL = 'examples/src/hello_world/index.html'; + var URL = 'examples/src/hello_world/index_dynamic.html'; it('should greet', function() { browser.get(URL); diff --git a/modules/examples/src/hello_world/index.html b/modules/examples/src/hello_world/index.html index 16b869170d..1e6008f42b 100644 --- a/modules/examples/src/hello_world/index.html +++ b/modules/examples/src/hello_world/index.html @@ -1,6 +1,6 @@ - Hello Angular 2.0 (Reflection) + Hello Angular 2.0 Loading... diff --git a/modules/examples/src/hello_world/index.js b/modules/examples/src/hello_world/index.js index c00cb67d87..c7802178f9 100644 --- a/modules/examples/src/hello_world/index.js +++ b/modules/examples/src/hello_world/index.js @@ -1,14 +1,24 @@ -import * as app from './index_common'; +import {HelloCmp} from './index_common'; +import {bootstrap} from 'angular2/angular2'; import {reflector} from 'angular2/src/reflection/reflection'; import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; export function main() { - // Initializing the reflector is only required for the Dart version of the application. - // When using Dart, the reflection information is not embedded by default in the source code - // to keep the size of the generated file small. Importing ReflectionCapabilities and initializing - // the reflector is required to use the reflection information from Dart mirrors. - // Dart mirrors are not intended to be use in production code where the transformers generate a - // more optimal static configuration, see index_static.js for an example. + // For Dart users: Initializing the reflector is only required for the Dart version of the + // application. When using Dart, the reflection information is not embedded by default in the + // source code to keep the size of the generated file small. Importing ReflectionCapabilities and + // initializing the reflector is required to use the reflection information from Dart mirrors. + // Dart mirrors are not intended to be use in production code. + // Angular 2 provides a transformer which generates static code rather than rely on reflection. + // For an example, run `pub serve` on the Dart application and inspect this file in your browser. reflector.reflectionCapabilities = new ReflectionCapabilities(); - app.main(); + + // Bootstrapping only requires specifying a root component. + // The boundary between the Angular application and the rest of the page is + // the shadowDom of this root component. + // The selector of the component passed in is used to find where to insert the + // application. + // You can use the light dom of the tag as temporary content (for + // example 'Loading...') before the application is ready. + bootstrap(HelloCmp); } diff --git a/modules/examples/src/hello_world/index_common.js b/modules/examples/src/hello_world/index_common.js index bdf9cfb3cc..168aaa6442 100644 --- a/modules/examples/src/hello_world/index_common.js +++ b/modules/examples/src/hello_world/index_common.js @@ -1,4 +1,4 @@ -import {bootstrap, Component, Decorator, View, NgElement} from 'angular2/angular2'; +import {Component, Decorator, View, NgElement} from 'angular2/angular2'; import {Injectable} from 'angular2/di'; // Angular 2.0 supports 3 basic types of directives: @@ -30,7 +30,7 @@ import {Injectable} from 'angular2/di'; // misspelled). directives: [RedDec] }) -class HelloCmp { +export class HelloCmp { greeting: string; constructor(service: GreetingService) { this.greeting = service.greeting; @@ -61,14 +61,3 @@ class GreetingService { this.greeting = 'hello'; } } - -export function main() { - // Bootstrapping only requires specifying a root component. - // The boundary between the Angular application and the rest of the page is - // the shadowDom of this root component. - // The selector of the component passed in is used to find where to insert the - // application. - // You can use the light dom of the tag as temporary content (for - // example 'Loading...') before the application is ready. - bootstrap(HelloCmp); -} diff --git a/modules/examples/src/hello_world/index_static.html b/modules/examples/src/hello_world/index_dynamic.html similarity index 68% rename from modules/examples/src/hello_world/index_static.html rename to modules/examples/src/hello_world/index_dynamic.html index f6f1b5bb40..16b869170d 100644 --- a/modules/examples/src/hello_world/index_static.html +++ b/modules/examples/src/hello_world/index_dynamic.html @@ -1,6 +1,6 @@ - Hello Angular 2.0 (Static) + Hello Angular 2.0 (Reflection) Loading... diff --git a/modules/examples/src/hello_world/index_dynamic.js b/modules/examples/src/hello_world/index_dynamic.js new file mode 100644 index 0000000000..fcc9b7120c --- /dev/null +++ b/modules/examples/src/hello_world/index_dynamic.js @@ -0,0 +1,11 @@ +import {HelloCmp} from './index_common'; +import {bootstrap} from 'angular2/angular2'; +import {reflector} from 'angular2/src/reflection/reflection'; +import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; + +export function main() { + // This entry point is not transformed and exists for testing purposes. + // See index.js for an explanation. + reflector.reflectionCapabilities = new ReflectionCapabilities(); + bootstrap(HelloCmp); +} diff --git a/modules/examples/src/hello_world/index_static.js b/modules/examples/src/hello_world/index_static.js deleted file mode 100644 index c3c9d32210..0000000000 --- a/modules/examples/src/hello_world/index_static.js +++ /dev/null @@ -1,306 +0,0 @@ -import * as app from './index_common'; - -import {Component, Decorator, View, NgElement} from 'angular2/angular2'; -import {Lexer, Parser, ChangeDetection, ChangeDetector, PipeRegistry, DynamicChangeDetection} from 'angular2/change_detection'; -import {ExceptionHandler} from 'angular2/src/core/exception_handler'; -import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle'; - -import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler'; -import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader'; -import {ShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/shadow_dom_strategy'; -import {NativeShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/native_shadow_dom_strategy'; -import {EmulatedUnscopedShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/emulated_unscoped_shadow_dom_strategy'; -import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader'; -import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver'; -import {XHR} from 'angular2/src/services/xhr'; -import {XHRImpl} from 'angular2/src/services/xhr_impl'; -import {UrlResolver} from 'angular2/src/services/url_resolver'; -import {StyleUrlResolver} from 'angular2/src/render/dom/shadow_dom/style_url_resolver'; -import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mapper'; -import {StyleInliner} from 'angular2/src/render/dom/shadow_dom/style_inliner'; -import {EventManager} from 'angular2/src/render/dom/events/event_manager'; -import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader'; -import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability'; - -import {reflector} from 'angular2/src/reflection/reflection'; - -import {ViewFactory, VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_factory'; -import {AppViewHydrator} from 'angular2/src/core/compiler/view_hydrator'; -import {ProtoViewFactory} from 'angular2/src/core/compiler/proto_view_factory'; -import {Renderer} from 'angular2/src/render/api'; -import {DirectDomRenderer} from 'angular2/src/render/dom/direct_dom_renderer'; -import * as rc from 'angular2/src/render/dom/compiler/compiler'; -import * as rvf from 'angular2/src/render/dom/view/view_factory'; -import * as rvh from 'angular2/src/render/dom/view/view_hydrator'; -import {Inject} from 'angular2/di'; - -function setup() { - reflector.registerType(app.HelloCmp, { - "factory": (service) => new app.HelloCmp(service), - "parameters": [[app.GreetingService]], - "annotations" : [ - new Component({ - selector: 'hello-app', - injectables: [app.GreetingService] - }), - new View({ - directives: [app.RedDec], - template: `
{{greeting}} world!
- ` - })] - }); - - reflector.registerType(app.RedDec, { - "factory": (el) => new app.RedDec(el), - "parameters": [[NgElement]], - "annotations" : [new Decorator({selector: '[red]'})] - }); - - reflector.registerType(app.GreetingService, { - "factory": () => new app.GreetingService(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(Compiler, { - "factory": (reader, compilerCache, tplResolver, cmpUrlMapper, urlResolver, renderer, - protoViewFactory) => - new Compiler(reader, compilerCache, tplResolver, cmpUrlMapper, urlResolver, renderer, - protoViewFactory), - "parameters": [[DirectiveMetadataReader], [CompilerCache], [TemplateResolver], [ComponentUrlMapper], - [UrlResolver], [Renderer], [ProtoViewFactory]], - "annotations": [] - }); - - reflector.registerType(CompilerCache, { - "factory": () => new CompilerCache(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(Parser, { - "factory": (lexer) => new Parser(lexer), - "parameters": [[Lexer]], - "annotations": [] - }); - - reflector.registerType(TemplateLoader, { - "factory": (xhr, urlResolver) => new TemplateLoader(xhr, urlResolver), - "parameters": [[XHR], [UrlResolver]], - "annotations": [] - }); - - reflector.registerType(TemplateResolver, { - "factory": () => new TemplateResolver(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(XHR, { - "factory": () => new XHRImpl(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(DirectiveMetadataReader, { - "factory": () => new DirectiveMetadataReader(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(Lexer, { - "factory": () => new Lexer(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(ExceptionHandler, { - "factory": () => new ExceptionHandler(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(LifeCycle, { - "factory": (exHandler, cd) => new LifeCycle(exHandler, cd), - "parameters": [[ExceptionHandler], [ChangeDetector]], - "annotations": [] - }); - - reflector.registerType(ShadowDomStrategy, { - "factory": (strategy) => strategy, - "parameters": [[NativeShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(NativeShadowDomStrategy, { - "factory": (styleUrlResolver) => new NativeShadowDomStrategy(styleUrlResolver), - "parameters": [[StyleUrlResolver]], - "annotations": [] - }); - - reflector.registerType(EmulatedUnscopedShadowDomStrategy, { - "factory": (styleUrlResolver) => new EmulatedUnscopedShadowDomStrategy(styleUrlResolver, null), - "parameters": [[StyleUrlResolver]], - "annotations": [] - }); - - reflector.registerType(StyleUrlResolver, { - "factory": (urlResolver) => new StyleUrlResolver(urlResolver), - "parameters": [[UrlResolver]], - "annotations": [] - }); - - reflector.registerType(UrlResolver, { - "factory": () => new UrlResolver(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(ComponentUrlMapper, { - "factory": () => new ComponentUrlMapper(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(StyleInliner, { - "factory": (xhr, styleUrlResolver, urlResolver) => - new StyleInliner(xhr, styleUrlResolver, urlResolver), - "parameters": [[XHR], [StyleUrlResolver], [UrlResolver]], - "annotations": [] - }); - - reflector.registerType(EventManager, { - "factory": () => new EventManager([], null), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(DynamicComponentLoader, { - "factory": (compiler, reader, viewFactory, appViewHydrator) => - new DynamicComponentLoader(compiler, reader, viewFactory, appViewHydrator), - "parameters": [[Compiler], [DirectiveMetadataReader], [ViewFactory], [AppViewHydrator]], - "annotations": [] - }); - - reflector.registerType(rc.DefaultCompiler, { - "factory": (parser, shadowDomStrategy, templateLoader) => - new rc.DefaultCompiler(parser, shadowDomStrategy, templateLoader), - "parameters": [[Parser], [ShadowDomStrategy], [TemplateLoader]], - "annotations": [] - }); - - reflector.registerType(rvf.ViewFactory, { - "factory": (capacity, eventManager, shadowDomStrategy) => - new rvf.ViewFactory(capacity, eventManager, shadowDomStrategy), - "parameters": [[new Inject(rvf.VIEW_POOL_CAPACITY)], [EventManager], [ShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(rvf.VIEW_POOL_CAPACITY, { - "factory": () => 10000, - "parameters": [], - "annotations": [] - }); - - reflector.registerType(rvh.RenderViewHydrator, { - "factory": (eventManager, viewFactory) => - new rvh.RenderViewHydrator(eventManager, viewFactory), - "parameters": [[rvf.ViewFactory], [EventManager]], - "annotations": [] - }); - - reflector.registerType(ProtoViewFactory, { - "factory": (changeDetection) => - new ProtoViewFactory(changeDetection), - "parameters": [[ChangeDetection]], - "annotations": [] - }); - - reflector.registerType(ViewFactory, { - "factory": (capacity, renderer, appViewHydrator) => - new ViewFactory(capacity, renderer, appViewHydrator), - "parameters": [[new Inject(VIEW_POOL_CAPACITY)],[Renderer],[AppViewHydrator]], - "annotations": [] - }); - - reflector.registerType(AppViewHydrator, { - "factory": (renderer) => - new AppViewHydrator(renderer), - "parameters": [[Renderer]], - "annotations": [] - }); - - reflector.registerType(VIEW_POOL_CAPACITY, { - "factory": () => 10000, - "parameters": [], - "annotations": [] - }); - - reflector.registerType(TestabilityRegistry, { - "factory": () => new TestabilityRegistry(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(Testability, { - "factory": () => new Testability(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(DynamicChangeDetection, { - "factory": (registry) => new DynamicChangeDetection(registry), - "parameters": [[PipeRegistry]], - "annotations": [] - }); - - reflector.registerType(DirectDomRenderer, { - "factory": (renderCompiler, renderViewFactory, renderViewHydrator, shadowDomStrategy) => - new DirectDomRenderer(renderCompiler, renderViewFactory, renderViewHydrator, shadowDomStrategy), - "parameters": [[rc.Compiler], [rvf.ViewFactory], [rvh.RenderViewHydrator], [ShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(rc.DefaultCompiler, { - "factory": (parser, shadowDomStrategy, templateLoader) => - new rc.DefaultCompiler(parser, shadowDomStrategy, templateLoader), - "parameters": [[Parser], [ShadowDomStrategy], [TemplateLoader]], - "annotations": [] - }); - - reflector.registerType(rvf.ViewFactory, { - "factory": (capacity, eventManager, shadowDomStrategy) => - new rvf.ViewFactory(capacity, eventManager, shadowDomStrategy), - "parameters": [[new Inject(rvf.VIEW_POOL_CAPACITY)], [EventManager], [ShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(rvf.VIEW_POOL_CAPACITY, { - "factory": () => 10000, - "parameters": [], - "annotations": [] - }); - - reflector.registerType(VIEW_POOL_CAPACITY, { - "factory": () => 10000, - "parameters": [], - "annotations": [] - }); - - reflector.registerGetters({ - "greeting": (a) => a.greeting - }); - - reflector.registerSetters({ - "greeting": (a,v) => a.greeting = v - }); - - reflector.registerMethods({ - "changeGreeting": (obj, args) => obj.changeGreeting() - }); -} - -export function main() { - setup(); - app.main(); -}