Skip to content

Commit 00e2d70

Browse files
author
Tim Blasi
committed
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 angular#495
1 parent e52d710 commit 00e2d70

File tree

8 files changed

+35
-349
lines changed

8 files changed

+35
-349
lines changed

gulpfile.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -355,24 +355,6 @@ gulp.task('serve/benchmarks_external.dart', pubserve(gulp, gulpPlugins, {
355355
path: CONFIG.dest.dart + '/benchmarks_external'
356356
}));
357357

358-
gulp.task('serve/examples.dart.static', pubserve(gulp, gulpPlugins, {
359-
command: DART_SDK.PUB,
360-
mode: 'ngstatic',
361-
path: CONFIG.dest.dart + '/examples'
362-
}));
363-
364-
gulp.task('serve/benchmarks.dart.static', pubserve(gulp, gulpPlugins, {
365-
command: DART_SDK.PUB,
366-
mode: 'ngstatic',
367-
path: CONFIG.dest.dart + '/benchmarks'
368-
}));
369-
370-
gulp.task('serve/benchmarks_external.dart.static', pubserve(gulp, gulpPlugins, {
371-
command: DART_SDK.PUB,
372-
mode: 'ngstatic',
373-
path: CONFIG.dest.dart + '/benchmarks_external'
374-
}));
375-
376358
// --------------
377359
// doc generation
378360
var Dgeni = require('dgeni');

modules/examples/e2e_test/hello_world/hello_world_spec.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ describe('hello world', function () {
44
afterEach(testUtil.verifyNoBrowserErrors);
55

66
describe('static reflection', function() {
7-
var URL = 'examples/src/hello_world/index_static.html';
7+
var URL = 'examples/src/hello_world/index.html';
88

99
it('should greet', function() {
1010
browser.get(URL);
@@ -21,7 +21,7 @@ describe('hello world', function () {
2121
});
2222

2323
describe('dynamic reflection', function() {
24-
var URL = 'examples/src/hello_world/index.html';
24+
var URL = 'examples/src/hello_world/index_dynamic.html';
2525

2626
it('should greet', function() {
2727
browser.get(URL);

modules/examples/src/hello_world/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!doctype html>
22
<html>
3-
<title>Hello Angular 2.0 (Reflection)</title>
3+
<title>Hello Angular 2.0</title>
44
<body>
55
<hello-app>
66
Loading...
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
import * as app from './index_common';
1+
import {HelloCmp} from './index_common';
2+
import {bootstrap} from 'angular2/angular2';
23
import {reflector} from 'angular2/src/reflection/reflection';
34
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
45

56
export function main() {
6-
// Initializing the reflector is only required for the Dart version of the application.
7-
// When using Dart, the reflection information is not embedded by default in the source code
8-
// to keep the size of the generated file small. Importing ReflectionCapabilities and initializing
9-
// the reflector is required to use the reflection information from Dart mirrors.
10-
// Dart mirrors are not intended to be use in production code where the transformers generate a
11-
// more optimal static configuration, see index_static.js for an example.
7+
// For Dart users: Initializing the reflector is only required for the Dart version of the
8+
// application. When using Dart, the reflection information is not embedded by default in the
9+
// source code to keep the size of the generated file small. Importing ReflectionCapabilities and
10+
// initializing the reflector is required to use the reflection information from Dart mirrors.
11+
// Dart mirrors are not intended to be use in production code.
12+
// Angular 2 provides a transformer which generates static code rather than rely on reflection.
13+
// For an example, run `pub serve` on the Dart application and inspect this file in your browser.
1214
reflector.reflectionCapabilities = new ReflectionCapabilities();
13-
app.main();
15+
16+
// Bootstrapping only requires specifying a root component.
17+
// The boundary between the Angular application and the rest of the page is
18+
// the shadowDom of this root component.
19+
// The selector of the component passed in is used to find where to insert the
20+
// application.
21+
// You can use the light dom of the <hello-app> tag as temporary content (for
22+
// example 'Loading...') before the application is ready.
23+
bootstrap(HelloCmp);
1424
}

modules/examples/src/hello_world/index_common.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {bootstrap, Component, Decorator, View, NgElement} from 'angular2/angular2';
1+
import {Component, Decorator, View, NgElement} from 'angular2/angular2';
22
import {Injectable} from 'angular2/di';
33

44
// Angular 2.0 supports 3 basic types of directives:
@@ -30,7 +30,7 @@ import {Injectable} from 'angular2/di';
3030
// misspelled).
3131
directives: [RedDec]
3232
})
33-
class HelloCmp {
33+
export class HelloCmp {
3434
greeting: string;
3535
constructor(service: GreetingService) {
3636
this.greeting = service.greeting;
@@ -61,14 +61,3 @@ class GreetingService {
6161
this.greeting = 'hello';
6262
}
6363
}
64-
65-
export function main() {
66-
// Bootstrapping only requires specifying a root component.
67-
// The boundary between the Angular application and the rest of the page is
68-
// the shadowDom of this root component.
69-
// The selector of the component passed in is used to find where to insert the
70-
// application.
71-
// You can use the light dom of the <hello-app> tag as temporary content (for
72-
// example 'Loading...') before the application is ready.
73-
bootstrap(HelloCmp);
74-
}

modules/examples/src/hello_world/index_static.html renamed to modules/examples/src/hello_world/index_dynamic.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!doctype html>
22
<html>
3-
<title>Hello Angular 2.0 (Static)</title>
3+
<title>Hello Angular 2.0 (Reflection)</title>
44
<body>
55
<hello-app>
66
Loading...
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {HelloCmp} from './index_common';
2+
import {bootstrap} from 'angular2/angular2';
3+
import {reflector} from 'angular2/src/reflection/reflection';
4+
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
5+
6+
export function main() {
7+
// This entry point is not transformed and exists for testing purposes.
8+
// See index.js for an explanation.
9+
reflector.reflectionCapabilities = new ReflectionCapabilities();
10+
bootstrap(HelloCmp);
11+
}

0 commit comments

Comments
 (0)