Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit c73a0c7

Browse files
committed
chore(docs): more detail for app:dynamic in 0.9.11
1 parent e46cc23 commit c73a0c7

File tree

4 files changed

+116
-38
lines changed

4 files changed

+116
-38
lines changed

example/web/animation.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ class AnimationDemoController {
1717
var currentPage = "About";
1818
}
1919

20+
class AnimationDemoModule extends Module {
21+
AnimationDemoModule() {
22+
install(new NgAnimateModule());
23+
type(RepeatDemoComponent);
24+
type(VisibilityDemoComponent);
25+
type(StressDemoComponent);
26+
type(CssDemoComponent);
27+
type(AnimationDemoController);
28+
}
29+
}
2030
main() {
2131
dynamicApplication()
22-
.addModule(new Module()
23-
..type(RepeatDemoComponent)
24-
..type(VisibilityDemoComponent)
25-
..type(StressDemoComponent)
26-
..type(CssDemoComponent)
27-
..type(AnimationDemoController))
28-
.addModule(new NgAnimateModule())
32+
.addModule(new AnimationDemoModule())
2933
.run();
3034
}

lib/angular_dynamic.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
* Bootstrapping for Angular applications via [dart:mirrors](https://api.dartlang
33
* .org/apidocs/channels/stable/dartdoc-viewer/dart-mirrors) for development.
44
*
5+
* Angular apps that use [dynamicApplication](#angular-app-dynamic@id_dynamicApplication) rely on
6+
* dynamic transformation at compile time to generate the getters, setters, annotations, and
7+
* factories needed for tree shaking during compilation with `dart2js`. See the [angular:app]
8+
* (#angular-app) library for a discussion of how this works.
59
*/
610
library angular.app.dynamic;
711

lib/angular_static.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
/**
22
* Bootstrapping for Angular applications via code generation, for production.
33
*
4+
* Most angular.dart apps rely on dynamic transformation at compile time to generate the artifacts
5+
* needed for tree shaking during compilation with `dart2js`. However,
6+
* if your deployment environment makes it impossible for you to use transformers,
7+
* you can call [staticApplication](#angular-app-static@id_staticApplication)
8+
* directly in your `main()` function, and explicitly define the getters, setters, annotations, and
9+
* factories yourself.
10+
*
11+
* import 'package:angular/angular.dart';
12+
* import 'package:angular/angular_static.dart';
13+
*
14+
* class MyModule extends Module {
15+
* MyModule() {
16+
* type(HelloWorldController);
17+
* }
18+
* }
19+
*
20+
* main() {
21+
* staticApplication()
22+
* .addModule(new MyModule())
23+
* .run();
24+
* }
25+
*
26+
* Note that you must explicitly import both
27+
* `angular.dart` and `angular_static.dart` at the start of your file. See [staticApplication]
28+
* (#angular-app-static@id_staticApplication) for more on explicit definitions required with this
29+
* library.
30+
*
431
*/
532
library angular.app.static;
633

lib/bootstrap.dart

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,66 @@
11
/**
22
* Bootstrapping for Angular applications via [app:dynamic](#angular-app-dynamic) for development,
3-
* or
4-
* [app:static](#angular-app-static) for production.
3+
* or [app:static](#angular-app-static) for production.
54
*
5+
* In your `main()` function, you bootstrap Angular by explicitly defining and adding a module for
6+
* your app:
7+
*
8+
* import 'package:angular/angular.dart';
9+
* import 'package:angular/angular_dynamic.dart';
10+
*
11+
* class MyModule extends Module {
12+
* MyModule() {
13+
* type(HelloWorldController);
14+
* }
15+
* }
16+
*
17+
* main() {
18+
* dynamicApplication()
19+
* .addModule(new MyModule())
20+
* .run();
21+
* }
22+
*
23+
* In the code above, we use [dynamicApplication](#angular-app-dynamic) to
24+
* take advantage of [dart:mirrors]
25+
* (https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-mirrors) during
26+
* development. When you run the app in Dartium, you are using the implementation found under
27+
* [app:dynamic](#angular-app-dynamic). Note also that you must explicitly import both
28+
* `angular.dart` and `angular_dynamic.dart` at the start of your file.
29+
*
30+
* For production, transformers defined in your `pubspec.yaml` file convert the compiled code to
31+
* use the [app:static](#angular-app-static) implementation when you run `pub build`. Instead of
32+
* relying on mirrors, this automatically generates the getters, setters, annotations, and factories
33+
* needed by Dart for tree shaking in dart2js, ensuring that your final JavaScript code contains
34+
* only what is used by the root Injector that ngApp creates.
35+
*
36+
* Add the transformers rule shown below to your `pubspec.yaml`:
37+
*
38+
* name: angular_dart_example
39+
* version: 0.0.1
40+
* dependencies:
41+
* angular: '>= 0.9.11'
42+
* browser: any
43+
* unittest: any
44+
*
45+
* transformers:
46+
* - angular
47+
*
48+
* If your app structure makes use of directories for storing your templates,
49+
* you must also specify rules for `html_files` to ensure that the transformers pick up those
50+
* files. You only need to specify the HTML files; the parser will infer the correct `.dart` and
51+
* CSS files to include.
52+
*
53+
* For example:
54+
*
55+
* transformers:
56+
* - angular:
57+
* html_files:
58+
* - lib/_somelibrary/_some_component.html
59+
*
60+
* If you need a way to build your app without transformers, you can use
61+
* [staticApplication](#angular-app-static@id_staticApplication) directly, instead of
62+
* [dynamicApplication](#angular-app-dynamic@id_dynamicApplication). See the documentation for
63+
* the [app:static](#angular-app-static) library definition for more on this use case.
664
*/
765
library angular.app;
866

@@ -21,17 +79,15 @@ import 'package:angular/routing/module.dart';
2179
import 'package:angular/introspection_js.dart';
2280

2381
/**
24-
* This is the top level module which describes the core angular of angular including filters and
25-
* directives. The module is automatically included with [Application]
82+
* This is the top level module which describes all Angular components,
83+
* including services, filters and directives. When writing an Angular application,
84+
* AngularModule is automatically included.
2685
*
27-
* The Module is made up of
86+
* You can use AngularModule explicitly when creating a custom Injector that needs to know
87+
* about Angular services, filters, and directives. When writing tests, this is typically done for
88+
* you by the [SetUpInjector](#angular-mock@id_setUpInjector) method.
2889
*
29-
* - [NgCoreModule]
30-
* - [NgCoreDomModule]
31-
* - [NgDirectiveModule]
32-
* - [NgFilterModule]
33-
* - [NgPerfModule]
34-
* - [NgRoutingModule]
90+
3591
*/
3692
class AngularModule extends Module {
3793
AngularModule() {
@@ -48,27 +104,14 @@ class AngularModule extends Module {
48104
}
49105

50106
/**
51-
* Application is how you configure and run an Angular application. Application is abstract. There are two
52-
* implementations: one is dynamic, using Mirrors; the other is static, using code generation.
53-
*
54-
* To create an Application, import angular_dynamic.dart and call dynamicApplication like so:
55-
*
56-
* import 'package:angular/angular.dart';
57-
* import 'package:angular/angular_dynamic.dart';
58-
*
59-
* class HelloWorldController {
60-
* ...
61-
* }
62-
*
63-
* main() {
64-
* dynamicApplication()
65-
* .addModule(new Module()..type(HelloWorldController))
66-
* .run();
67-
* }
68-
*
69-
* On `pub build`, dynamicApplication becomes staticApplication, as pub generates the getters,
70-
* setters, annotations, and factories for the root Injector that [ngApp] creates. This
107+
* Application is how you configure and run an Angular application. There are two
108+
* implementations for this abstract class:
71109
*
110+
* - [app:dynamic](#angular-app-dynamic) for development, which uses transformers to generate the
111+
* getters, setters, annotations, and factories needed by [dart:mirrors](https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-mirrors) for tree shaking
112+
* - [app:static](#angular-app-static), for apps that explicitly specify their own getters,
113+
* setters, annotations, and factories and do not rely on transformation or [dart:mirrors]
114+
* (https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-mirrors)
72115
*
73116
*/
74117

0 commit comments

Comments
 (0)