From c59cc8631a57fd21443ceccbe81e826aca63af29 Mon Sep 17 00:00:00 2001 From: Rado Kirov Date: Tue, 2 Dec 2014 19:14:48 -0800 Subject: [PATCH] feat(examples): adds static dart hello world example. Use gulp examples/pub.serve to start up the server and go to http://localhost:8080/index_static.html to see the static app. --- modules/core/src/application.js | 3 - modules/examples/pubspec.yaml | 5 ++ .../examples/src/hello_world/static_app.js | 82 +++++++++++++++++++ modules/examples/web/index_static.html | 20 +++++ modules/examples/web/main.dart | 11 ++- modules/examples/web/main_static.dart | 4 + 6 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 modules/examples/src/hello_world/static_app.js create mode 100644 modules/examples/web/index_static.html create mode 100644 modules/examples/web/main_static.dart diff --git a/modules/core/src/application.js b/modules/core/src/application.js index 2d4d050dc3..68813cc18f 100644 --- a/modules/core/src/application.js +++ b/modules/core/src/application.js @@ -4,7 +4,6 @@ import {DOM, Element} from 'facade/dom'; import {Compiler} from './compiler/compiler'; import {ProtoView} from './compiler/view'; import {Reflector, reflector} from 'reflection/reflection'; -import {ReflectionCapabilities} from 'reflection/reflection_capabilities'; import {Parser} from 'change_detection/parser/parser'; import {Lexer} from 'change_detection/parser/lexer'; import {ChangeDetector} from 'change_detection/change_detector'; @@ -74,8 +73,6 @@ function _injectorBindings(appComponentType) { // Multiple calls to this method are allowed. Each application would only share // _rootInjector, which is not user-configurable by design, thus safe to share. export function bootstrap(appComponentType: Type, bindings=null) { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - // TODO(rado): prepopulate template cache, so applications with only // index.html and main.js are possible. if (isBlank(_rootInjector)) _rootInjector = new Injector(_rootBindings); diff --git a/modules/examples/pubspec.yaml b/modules/examples/pubspec.yaml index d7b2a9ded8..6c8ace8da7 100644 --- a/modules/examples/pubspec.yaml +++ b/modules/examples/pubspec.yaml @@ -4,6 +4,8 @@ environment: dependencies: facade: path: ../facade + reflection: + path: ../reflection core: path: ../core browser: '>=0.10.0 <0.11.0' @@ -11,3 +13,6 @@ dev_dependencies: test_lib: path: ../test_lib guinness: ">=0.1.16 <0.2.0" +transformers: + - $dart2js: + minify: true diff --git a/modules/examples/src/hello_world/static_app.js b/modules/examples/src/hello_world/static_app.js new file mode 100644 index 0000000000..58323a6e3e --- /dev/null +++ b/modules/examples/src/hello_world/static_app.js @@ -0,0 +1,82 @@ +import * as app from './app'; + +import {Component, Decorator, TemplateConfig, NgElement} from 'core/core'; +import {Parser} from 'change_detection/parser/parser'; +import {Lexer} from 'change_detection/parser/lexer'; + +import {Compiler} from 'core/compiler/compiler'; +import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader'; +import {TemplateLoader} from 'core/compiler/template_loader'; + +import {reflector} from 'reflection/reflection'; + +function setup() { + reflector.registerType(app.HelloCmp, { + "factory": (service) => new app.HelloCmp(service), + "parameters": [[app.GreetingService]], + "annotations" : [new Component({ + selector: 'hello-app', + componentServices: [app.GreetingService], + template: new TemplateConfig({ + directives: [app.RedDec], + inline: `{{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": (templateLoader, reader, parser) => new Compiler(templateLoader, reader, parser), + "parameters": [[TemplateLoader], [DirectiveMetadataReader], [Parser]], + "annotations": [] + }); + + + reflector.registerType(Parser, { + "factory": (lexer) => new Parser(lexer), + "parameters": [[Lexer]], + "annotations": [] + }); + + reflector.registerType(TemplateLoader, { + "factory": () => new TemplateLoader(), + "parameters": [], + "annotations": [] + }); + + reflector.registerType(DirectiveMetadataReader, { + "factory": () => new DirectiveMetadataReader(), + "parameters": [], + "annotations": [] + }); + + reflector.registerType(Lexer, { + "factory": () => new Lexer(), + "parameters": [], + "annotations": [] + }); + + + reflector.registerGetters({ + "greeting": (a) => a.greeting + }); + + reflector.registerSetters({ + "greeting": (a,v) => a.greeting = v + }); +} + +export function main() { + setup(); + app.main(); +} diff --git a/modules/examples/web/index_static.html b/modules/examples/web/index_static.html new file mode 100644 index 0000000000..7c27acdc32 --- /dev/null +++ b/modules/examples/web/index_static.html @@ -0,0 +1,20 @@ + + + + Hello Angular 2.0 (Dart Static) + + + + + + Loading... + + + + + diff --git a/modules/examples/web/main.dart b/modules/examples/web/main.dart index d4dd39d888..0c52222623 100644 --- a/modules/examples/web/main.dart +++ b/modules/examples/web/main.dart @@ -1,4 +1,11 @@ -import 'packages/examples/hello_world/app.dart' as HelloWorldApp; +import 'package:examples/hello_world/app.dart' as HelloWorldApp; +import 'package:reflection/reflection_capabilities.dart'; +import 'package:reflection/reflection.dart'; // TODO(rado): templatize and make reusable for all examples. -main() => HelloWorldApp.main(); +main() { + // enable mirrors and reflection. + // see static_app.js for an example of a static app. + reflector.reflectionCapabilities = new ReflectionCapabilities(); + HelloWorldApp.main(); +} diff --git a/modules/examples/web/main_static.dart b/modules/examples/web/main_static.dart new file mode 100644 index 0000000000..d2909919cd --- /dev/null +++ b/modules/examples/web/main_static.dart @@ -0,0 +1,4 @@ +import 'packages/examples/hello_world/static_app.dart' as HelloWorldApp; + +// TODO(rado): templatize and make reusable for all examples. +main() => HelloWorldApp.main();