Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 3bd646b

Browse files
committed
dart quickstart: add transformer, use alpha.25
1 parent 2f62173 commit 3bd646b

File tree

1 file changed

+137
-111
lines changed

1 file changed

+137
-111
lines changed

public/docs/dart/latest/quickstart.jade

Lines changed: 137 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,29 @@ p.
2121
Create a new directory, and put a file named
2222
<code>pubspec.yaml</code> in it.
2323

24-
pre.prettyprint
25-
code.
26-
&gt; mkdir hello_world
27-
&gt; cd hello_world
28-
&gt; vim pubspec.yaml # Use your favorite editor!
24+
code-example(language="sh").
25+
&gt; <span class="blk">mkdir hello_world</span>
26+
&gt; <span class="blk">cd hello_world</span>
27+
&gt; <span class="blk">vim pubspec.yaml</span> # Use your favorite editor!
2928

3029
p.
3130
In <code>pubspec.yaml</code>, add the angular2 and browser packages as dependencies.
3231
Angular 2 is changing rapidly, so specify an exact version:
33-
<b>2.0.0-alpha.23</b>.
34-
35-
pre.prettyprint.linenums.lang-basic
36-
code.
37-
name: hello_world
38-
version: 0.0.1
39-
dependencies:
40-
angular2: 2.0.0-alpha.23
41-
browser: any
32+
<b>2.0.0-alpha.25</b>.
33+
34+
code-example(language="yaml").
35+
name: hello_world
36+
version: 0.0.1
37+
dependencies:
38+
angular2: 2.0.0-alpha.25
39+
browser: any
4240
p.
4341
In the same directory, run <code>pub get</code>
4442
to install the angular2 and browser packages
4543
(along with the packages they depend on):
4644

47-
pre.prettyprint.lang-basic
48-
code.
49-
&gt; pub get
45+
code-example(language="sh").
46+
&gt; <span class="blk">pub get</span>
5047

5148
// PENDING: Create template? Link to pub/pubspec docs?
5249
// Is browser really needed?
@@ -60,25 +57,18 @@ p.
6057
Still in the same directory, create a <code>web</code> directory.
6158
Create a file under <code>web</code> named <code>main.dart</code>.
6259

63-
pre.prettyprint
64-
code.
65-
&gt; mkdir web
66-
&gt; vim web/main.dart # Use your favorite editor!
60+
code-example(language="sh").
61+
&gt; <span class="blk">mkdir web</span>
62+
&gt; <span class="blk">vim web/main.dart</span> # Use your favorite editor!
6763

6864
p.
6965
Edit <code>web/main.dart</code> to import the angular2 library
70-
and (for now) two reflection libraries:
66+
and two reflection libraries:
7167

72-
// pre.prettyprint.linenums
73-
pre.prettyprint
74-
code.
75-
import 'package:angular2/angular2.dart';
76-
77-
// These imports will go away soon:
78-
import 'package:angular2/src/reflection/reflection.dart' show reflector;
79-
import 'package:angular2/src/reflection/reflection_capabilities.dart' show ReflectionCapabilities;
80-
81-
// [PENDING: add line numbers once we can specify where they start]
68+
code-example(language="dart" format="linenums").
69+
import 'package:angular2/angular2.dart';
70+
import 'package:angular2/src/reflection/reflection.dart' show reflector;
71+
import 'package:angular2/src/reflection/reflection_capabilities.dart' show ReflectionCapabilities;
8272

8373
// STEP 3 - Define a component ##########################
8474
.l-main-section
@@ -89,19 +79,16 @@ p.
8979
Update <code>web/main.dart</code>, adding the following code
9080
after the imports:
9181

92-
pre.prettyprint
93-
code.
94-
@Component(
95-
selector: 'my-app'
96-
)
97-
@View(
98-
template: '&lt;h1&gt;Hello {{ name }}&lt;/h1&gt;'
99-
)
100-
class AppComponent {
101-
String name = 'Alice';
102-
}
103-
104-
// [PENDING: add line numbers once we can specify where they start]
82+
code-example(language="dart" format="linenums:5").
83+
@Component(
84+
selector: 'my-app'
85+
)
86+
@View(
87+
template: '&lt;h1&gt;Hello {{ name }}&lt;/h1&gt;'
88+
)
89+
class AppComponent {
90+
String name = 'Alice';
91+
}
10592

10693
p.
10794
The code you just added creates a component that
@@ -125,16 +112,13 @@ p.
125112
specify a <code>templateUrl</code> property
126113
and give it the path to the HTML file.
127114

128-
pre.prettyprint
129-
code.
130-
@Component(
131-
selector: 'my-app'
132-
)
133-
@View(
134-
template: '&lt;h1&gt;Hello {{ name }}&lt;/h1&gt;'
135-
)
136-
137-
// [PENDING: add line numbers once we can specify where they start]
115+
code-example(language="dart").
116+
@Component(
117+
selector: 'my-app'
118+
)
119+
@View(
120+
template: '&lt;h1&gt;Hello {{ name }}&lt;/h1&gt;'
121+
)
138122

139123
p.
140124
The annotations above specify an HTML tag of <code>&lt;my-app&gt;</code>
@@ -154,14 +138,10 @@ p.
154138
template renders, "Hello Alice" appears instead of
155139
<span ng-non-bindable>"Hello {{ name }}"</span>.
156140

157-
pre.prettyprint
158-
code.
159-
class AppComponent {
160-
String name = 'Alice';
161-
}
162-
163-
// [PENDING: add line numbers once we can specify where they start]
164-
141+
code-example(language="dart").
142+
class AppComponent {
143+
String name = 'Alice';
144+
}
165145

166146
// STEP 4 - Bootstrap ##########################
167147
.l-main-section
@@ -170,28 +150,19 @@ p.
170150
p.
171151
Add the following code to the bottom of <code>web/main.dart</code>:
172152

173-
pre.prettyprint
174-
code.
175-
main() {
176-
// Temporarily needed.
177-
reflector.reflectionCapabilities = new ReflectionCapabilities();
178-
179-
bootstrap(AppComponent);
180-
}
181-
182-
// [PENDING: add line numbers once we can specify where they start]
153+
code-example(language="dart" format="linenums:15").
154+
main() {
155+
reflector.reflectionCapabilities = new ReflectionCapabilities();
156+
bootstrap(AppComponent);
157+
}
183158

184159
p.
185160
This code adds a <code>main()</code> function
186161
that calls Angular's <code>bootstrap()</code> function.
187162
The argument to <code>bootstrap()</code> is the name of the component class
188163
you defined above.
189164

190-
p.
191-
Setting the value of
192-
<code>reflector.reflectionCapabilities</code>
193-
is a temporary workaround
194-
that you can remove once Angular's transformer is available.
165+
//- Explain why setting reflector.reflectionCapabilities is necessary.
195166
196167
197168
// STEP 5 - Declare the HTML ##########################
@@ -204,53 +175,108 @@ p.
204175
the following code,
205176
which loads <code>main.dart</code> and instantiates the my-app component:
206177

207-
pre.prettyprint.linenums
208-
code.
209-
&lt;!doctype html>
210-
&lt;html>
211-
&lt;head&gt;
212-
&lt;title&gt;Angular 2 Quickstart&lt;/title&gt;
213-
&lt;/head&gt;
214-
&lt;body>
215-
&lt;my-app>&lt;/my-app>
216-
217-
&lt;script type="application/dart" src="main.dart">&lt;/script>
218-
&lt;script src="packages/browser/dart.js">&lt;/script>
219-
&lt;/body>
220-
&lt;/html>
178+
code-example(language="html").
179+
&lt;!doctype html>
180+
&lt;html>
181+
&lt;head&gt;
182+
&lt;title&gt;Angular 2 Quickstart&lt;/title&gt;
183+
&lt;/head&gt;
184+
&lt;body>
185+
&lt;my-app>&lt;/my-app>
186+
187+
&lt;script type="application/dart" src="main.dart">&lt;/script>
188+
&lt;script src="packages/browser/dart.js">&lt;/script>
189+
&lt;/body>
190+
&lt;/html>
221191

222192
// STEP 6 - Build and run ##########################
223193
.l-main-section
224194

225195
h2#section-angular-run-app 6. Build and run your app
226196

227197
p.
228-
You have several options for running your app.
229-
The quickest and easiest, for now,
230-
is to open your project in <b>Dart Editor</b>,
231-
right-click <b>web/index.html</b>,
232-
and choose <b>Open in Dartium</b>.
233-
This starts a web server
234-
and opens your app in an experimental browser that contains the Dart VM.
235-
236-
// TODO: screenshot? embedded app?
198+
You have a few options for running your app.
199+
One is to launch a local HTTP server
200+
and then view the app in
201+
<a href="https://www.dartlang.org/tools/dartium/">Dartium</a>.
202+
You can use whatever server you like, such as Python's SimpleHTTPServer.
237203

238204
p.
239205
Another option is to build and serve the app using <code>pub serve</code>,
240-
and then run it by visiting <b>http://localhost:8080</b> in a browser.
241-
Generating the JavaScript takes a few seconds when you first visit the page,
242-
and the generated JavaScript is currently large.
243-
The generated JavaScript will be smaller once
244-
Angular's transformer becomes available.
206+
and then run it by visiting <b>http://localhost:8080</b> in any modern browser.
207+
Pub serve generates the JavaScript on the fly,
208+
which takes a few seconds when you first visit the page.
245209

246-
// [PENDING: Update when transformer is working!]
210+
p.
211+
Once the app is running,
212+
you should see <b>Hello Alice</b> in your browser window.
213+
214+
215+
// STEP 7 - Use the Angular transformer ##########################
216+
.l-main-section
217+
218+
h2#section-angular-run-app 7. Use the Angular transformer
219+
220+
p.
221+
To enable quick turnaround while you're developing an Angular app,
222+
the framework uses reflection via dart:mirrors.
223+
Unfortunately, mirror-using Dart code compiles to
224+
JavaScript code that's large and slow.
225+
To create more deployable JavaScript, use the Angular transformer.
226+
The transformer analyzes your code,
227+
converting reflection to static code
228+
that Dart's build tools can compile to faster, smaller JavaScript.
229+
230+
p.
231+
To use the Angular transformer,
232+
first add the highlighted lines to your <code>pubspec.yaml</code>:
233+
234+
code-example(language="yaml").
235+
name: hello_world
236+
version: 0.0.1
237+
dependencies:
238+
angular2: 2.0.0-alpha.25
239+
browser: any
240+
<span class="pnk">transformers:
241+
- angular2:
242+
entry_points: web/main.dart</span>
243+
p.
244+
Then build the JavaScript version using <code>pub build</code>:
245+
246+
code-example(language="basic").
247+
&gt; <span class="blk">pub build</span>
248+
Loading source assets...
249+
Loading angular2 transformers...
250+
INFO: Formatter is being overwritten.
251+
Building hello_world... (3.1s)
252+
[Info from Dart2JS]:
253+
Compiling hello_world|web/main.dart...
254+
[Info from Dart2JS]:
255+
Took 0:00:16.123086 to compile hello_world|web/main.dart.
256+
Built 41 files to "build".
257+
258+
p.
259+
The compiled JavaScript appears, along with supporting files,
260+
under the <code>build</code> directory.
261+
262+
p.
263+
For more information, see the
264+
<a href="https://github.com/angular/angular/wiki/Angular-2-Dart-Transformer">Angular
265+
transformer wiki page</a>.
247266

248267
// WHAT'S NEXT... ##########################
249268
.l-main-section
250269
h2#section-transpile Great job! Next step...
251270

252271
p.
253-
We plan to add a developer guide soon.
254-
Until then, check out <a href="resources.html">Angular Resources</a>.
255-
To learn more about Dart, go to
256-
<a href="https://www.dartlang.org">dartlang.org</a>.
272+
Follow the <a href="guide">developer guide</a>
273+
to continue playing with Angular 2 for Dart.
274+
275+
p.
276+
Or read more about Angular or Dart:
277+
278+
ul
279+
li
280+
<a href="resources.html">Angular resources</a>
281+
li
282+
<a href="https://www.dartlang.org">dartlang.org</a>

0 commit comments

Comments
 (0)