OLD | NEW |
---|---|
1 --- | 1 --- |
2 layout: homepage | 2 layout: homepage |
3 googleapi: true | 3 googleapi: true |
4 js: | 4 js: |
5 - url: /js/display-news.js | 5 - url: /js/display-news.js |
6 - url: /js/os-switcher.js | 6 - url: /js/os-switcher.js |
7 defer: true | 7 defer: true |
8 - url: /js/editor-downloads-analytics.js | 8 - url: /js/editor-downloads-analytics.js |
9 defer: true | 9 defer: true |
10 - url: /js/editor-version.js | 10 - url: /js/editor-version.js |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 <div id="feed-posts"> | 133 <div id="feed-posts"> |
134 </div> | 134 </div> |
135 </div> | 135 </div> |
136 </div> | 136 </div> |
137 </div> | 137 </div> |
138 </section> | 138 </section> |
139 | 139 |
140 <section id="code"> | 140 <section id="code"> |
141 <h1> Code </h1> | 141 <h1> Code </h1> |
142 | 142 |
143 <p> | 143 <p> |
144 Experiment with Dart right in your browser: | 144 You can find code examples in Dart Editor, |
sethladd
2013/08/08 19:00:32
maybe say "dart editor welcome page" ? How would I
Kathy Walrath
2013/08/08 23:16:59
Done.
| |
145 <a href="http://try.dartlang.org">try.dartlang.org</a> | 145 in the <a href="/samples/">Samples page</a>, |
146 and below. | |
147 You can also experiment with Dart right in your browser: | |
148 <a href="http://try.dartlang.org" target="_blank">try.dartlang.org</a> | |
146 </p> | 149 </p> |
147 | 150 |
148 <p> | 151 <div class="tabbable"> |
149 Here's some code from a Dart web app that uses Web UI. | 152 <ul class="nav nav-tabs"> |
150 To learn about web programming with Dart, try our | 153 <li class="active"><a href="#language" data-toggle="tab">Syntax</a></li> |
151 <a href="/docs/tutorials/">Dart tutorials</a>. | 154 <li><a href="#types" data-toggle="tab">Optional types</a>< /li> |
152 </p> | 155 <li><a href="#futures" data-toggle="tab">Futures</a></li> |
156 <li><a href="#webui" data-toggle="tab">Web UI</a></li> | |
157 </ul> | |
153 | 158 |
154 <div class="row-fluid"> | 159 <div class="tab-content"> |
155 <div class="span6" id="dart-code"> | 160 <div class="tab-pane active" id="language"> |
161 <p> | |
162 Dart aims to be unsurprising, | |
163 but it does add a few language features | |
164 to keep your code succinct yet understandable. | |
165 Read all about Dart syntax in the | |
166 <a href="/docs/dart-up-and-running/contents/ch02.html">Dart language tou r</a>. | |
167 </p> | |
168 | |
169 <div class="row-fluid"> | |
170 <div class="span10 offset1"> | |
171 {% prettify dart %} | |
172 [[highlight]]import[[/highlight]] 'dart:html'; // Dart supp orts libraries. | |
173 | |
174 // Define functions either inside or outside of classes. | |
175 startOrEndTest() { | |
176 // ... | |
177 } | |
178 | |
179 [[highlight]]class[[/highlight]] Rectangle implements Shape { // Declaring a class... | |
180 final num height, width; // ...with properties. | |
181 num [[highlight]]get[[/highlight]] area [[highlight]]=>[[/highlight]] height * width; // A property implemented with a getter. | |
182 // Also: function shorthand syntax (=>). | |
183 Rectangle([[highlight]]this.height, this.width[[/highlight]]); // Compact cons tructor syntax. | |
184 } | |
185 | |
186 // Every app has a main() function, where execution starts. | |
187 [[highlight]]main()[[/highlight]] { | |
188 // The cascade operator (..) saves you from repetitive typing. | |
189 query("#button") | |
190 [[highlight]]..[[/highlight]]text = "Run test" | |
191 [[highlight]]..[[/highlight]]onClick.listen(startOrEndTest); | |
192 } | |
193 {% endprettify %} | |
194 </div> | |
195 </div> | |
196 </div> | |
197 | |
198 <div class="tab-pane" id="types"> | |
199 <p> | |
200 Declaring types is optional in Dart. | |
201 These types don't affect the runtime behavior, | |
202 but you can use them to clarify APIs | |
203 and get better help from tools. | |
sethladd
2013/08/08 19:00:32
Can we add how you get better help? e.g. "e.g. wit
Kathy Walrath
2013/08/08 23:16:59
Done.
| |
204 For details, see | |
205 <a href="/articles/optional-types/">Optional Types in Dart</a>. | |
206 </p> | |
207 | |
208 <div class="row-fluid"> | |
209 <div class="span6" id="without-types"> | |
210 {% prettify dart %} | |
211 // Without types. | |
212 recalculate(origin, offset, estimate) { | |
213 // ... | |
214 } | |
215 {% endprettify %} | |
216 </div> | |
217 <div class="span6" id="with-types"> | |
218 {% prettify dart %} | |
219 // With types (and an optional parameter). | |
220 [[highlight]]num[[/highlight]] recalculate([[highlight]]Point[[/highlight]] orig in, | |
221 [[highlight]]num[[/highlight]] offset, | |
222 {[[highlight]]bool[[/highlight]] estimate:false}) { | |
223 // ... | |
224 } | |
225 {% endprettify %} | |
226 </div> | |
227 </div> | |
228 </div> | |
229 | |
230 <div class="tab-pane" id="futures"> | |
231 <p> | |
232 Functions that do potentially expensive work return Futures. | |
233 To specify what happens when the function's work is done, | |
234 invoke <code>then()</code> on the Future. | |
235 To handle errors, invoke <code>catchError()</code>. | |
236 Learn more by reading | |
237 <a href="/articles/using-future-based-apis/">Using Future Based APIs</a> . | |
238 </p> | |
239 | |
240 <div class="row-fluid"> | |
241 <div class="span10 offset1"> | |
242 | |
243 {% prettify dart %} | |
244 import 'dart:io'; | |
245 import 'dart:async'; | |
246 | |
247 void printDailyNewsDigest() { | |
248 File file = new File("dailyNewsDigest.txt"); | |
249 [[highlight]]file.readAsString()[[/highlight]] // readAsString() returns a F uture. | |
250 [[highlight]].then[[/highlight]]((content) { // Specifies what to do if th e Future completes successfully. | |
sethladd
2013/08/08 19:00:32
how about .then((content) => print(content)) here?
Kathy Walrath
2013/08/08 23:16:59
Done.
| |
251 print(content); // Executes when the file has been successfully read. | |
252 }) | |
253 [[highlight]].catchError((error)[[/highlight]] { // Specifies error handli ng code. | |
254 print("Sorry, no news today. Here's why:\n"); | |
255 print('$error'); | |
sethladd
2013/08/08 19:00:32
can you move this $error up to the first print? Yo
Kathy Walrath
2013/08/08 23:16:59
Done.
| |
256 }); | |
257 } | |
258 {% endprettify %} | |
259 </div> | |
260 </div> | |
261 </div> | |
262 <div class="tab-pane" id="webui"> | |
263 <p> | |
264 Here's an example of implementing a web app using the Web UI package. | |
265 To learn about web programming with Dart, try our | |
266 <a href="/docs/tutorials/">Dart tutorials</a>. | |
267 </p> | |
268 | |
269 <div class="row-fluid"> | |
270 <div class="span6" id="dart-code"> | |
156 {% prettify dart %} | 271 {% prettify dart %} |
157 // Dart code: | 272 // Dart code: |
158 import 'package:web_ui/web_ui.dart'; | 273 import 'package:web_ui/web_ui.dart'; |
159 | 274 |
160 @observable String myString = ''; | 275 @observable |
276 Shout [[highlight]]shout[[/highlight]] = new Shout(); | |
161 | 277 |
162 String get shouted => myString.toUpperCase(); | 278 @observable |
279 class Shout { | |
280 String [[highlight]]myString[[/highlight]] = ''; | |
281 | |
282 String get [[highlight]]shouted[[/highlight]] => myString.toUpperCase(); | |
163 | 283 |
164 String get palindrome => | 284 String get [[highlight]]palindrome[[/highlight]] => |
165 myString + myString.split('').reversed.join(); | 285 myString + myString.split('').reversed.join(); |
286 } | |
166 {% endprettify %} | 287 {% endprettify %} |
167 </div> | 288 </div> |
168 <div class="span6" id="html-code"> | 289 <div class="span6" id="html-code"> |
169 {% prettify html %} | 290 {% prettify html %} |
170 <!-- HTML code: --> | 291 <!-- HTML code: --> |
sethladd
2013/08/08 19:00:32
What about showing a snippet from a real tutorial,
Kathy Walrath
2013/08/08 23:16:59
I don't think there are any real Web UI tutorials
| |
171 <input type="text" bind-value="myString" | 292 ... |
172 placeholder="Type here"> | 293 <template id="stringManipulation" |
173 | 294 instantiate="if [[highlight]]shout[[/highlight]] != null"> |
sethladd
2013/08/08 19:00:32
s/instantiate/if
so, if="{{shout}}" should work (
Kathy Walrath
2013/08/08 23:16:59
I think "if" is a polymer-ism. At least, I couldn'
| |
174 <div> Shouted: {{'{{'}}shouted}} </div> | 295 <input type="text" |
175 <div> Palindromic: {{'{{'}}palindrome}} </div> | 296 bind-value="shout.[[highlight]]myString[[/highlight]]" |
297 placeholder="Type here"> | |
176 | 298 |
177 <script type="application/dart" src="little.dart"></script> | 299 <div> Shouted: {{'{{'}}shout.[[highlight]]shouted[[/highlight]]}} </div> |
300 <div> Palindromic: {{'{{'}}shout.[[highlight]]palindrome[[/highlight]]}} </div > | |
301 </template> | |
302 | |
303 <script type="application/dart" src="webui.dart"></script> | |
178 <script src="packages/browser/dart.js"></script> | 304 <script src="packages/browser/dart.js"></script> |
sethladd
2013/08/08 19:00:32
we can probably drop these two scripts, yes?
Kathy Walrath
2013/08/08 23:16:59
Done.
| |
305 ... | |
179 {% endprettify %} | 306 {% endprettify %} |
180 {% comment %} | 307 {% comment %} |
181 Beginning double curlies are processed by liquid, | 308 Beginning double curlies are processed by liquid, |
182 so you have to surround them in single quotes, | 309 so you have to surround them in single quotes, |
183 surrounded by double curlies. Yup. | 310 surrounded by double curlies. Yup. |
184 {% endcomment %} | 311 {% endcomment %} |
185 </div> | 312 </div> |
186 </div> <!-- code --> | 313 </div> <!-- code --> |
187 | 314 </div> |
315 </div> | |
316 </div> | |
188 </section> | 317 </section> |
189 | 318 |
190 | 319 |
191 <section id="get-started"> | 320 <section id="get-started"> |
192 | 321 |
193 <h1> Get started </h1> | 322 <h1> Get started </h1> |
194 | 323 |
195 <p> | 324 <p> |
196 Getting started with Dart is easy. | 325 Getting started with Dart is easy. |
197 Just download Dart, | 326 Just download Dart, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 You can write Dart apps using any recent version of | 397 You can write Dart apps using any recent version of |
269 {% include os-choices.html %} | 398 {% include os-choices.html %} |
270 The Dart development tools <b>do not support Windows XP</b>. | 399 The Dart development tools <b>do not support Windows XP</b>. |
271 Dart Editor requires Java version 6 or higher. | 400 Dart Editor requires Java version 6 or higher. |
272 </aside> | 401 </aside> |
273 | 402 |
274 </section> | 403 </section> |
275 | 404 |
276 </article> <!-- /.homepage --> | 405 </article> <!-- /.homepage --> |
277 | 406 |
OLD | NEW |