OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #import('dart:html'); | 5 #import('dart:html'); |
6 #import('dart:json'); | 6 #import('dart:json'); |
7 | 7 |
8 /** | 8 /** |
9 * Issue wraps JSON structure that describes a bug. | 9 * Issue wraps JSON structure that describes a bug. |
10 */ | 10 */ |
(...skipping 23 matching lines...) Expand all Loading... |
34 */ | 34 */ |
35 void processJson(Dynamic data) { | 35 void processJson(Dynamic data) { |
36 StringBuffer buffer = new StringBuffer(""); | 36 StringBuffer buffer = new StringBuffer(""); |
37 for (Issue issue in getIssues(data)) { | 37 for (Issue issue in getIssues(data)) { |
38 buffer.add(issue.toString()); | 38 buffer.add(issue.toString()); |
39 } | 39 } |
40 query("#container").innerHTML = buffer.toString(); | 40 query("#container").innerHTML = buffer.toString(); |
41 } | 41 } |
42 | 42 |
43 /** | 43 /** |
44 * Sends a XMLHTTPRequest and returns a future fo the date. | 44 * Sends a HTTPRequest and returns a future fo the date. |
45 */ | 45 */ |
46 Future<Dynamic> requestJson(String url) { | 46 Future<Dynamic> requestJson(String url) { |
47 Completer c = new Completer<Dynamic>(); | 47 Completer c = new Completer<Dynamic>(); |
48 void callback(XMLHttpRequest xhr) { | 48 void callback(HttpRequest xhr) { |
49 if (xhr.readyState == XMLHttpRequest.DONE) { | 49 if (xhr.readyState == HttpRequest.DONE) { |
50 c.complete(JSON.parse(xhr.response)); | 50 c.complete(JSON.parse(xhr.response)); |
51 } | 51 } |
52 }; | 52 }; |
53 new XMLHttpRequest.get(url, callback); | 53 new HttpRequest.get(url, callback); |
54 return c.future; | 54 return c.future; |
55 } | 55 } |
56 | 56 |
57 void main() { | 57 void main() { |
58 // Requests new issues (can=new) from the Dart issue database. | 58 // Requests new issues (can=new) from the Dart issue database. |
59 final String url = | 59 final String url = |
60 "https://code.google.com/feeds/issues/p/dart/issues/full?alt=json&can=new"; | 60 "https://code.google.com/feeds/issues/p/dart/issues/full?alt=json&can=new"; |
61 requestJson(url).then(processJson); | 61 requestJson(url).then(processJson); |
62 } | 62 } |
OLD | NEW |