Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: samples/newissues/newissues.dart

Issue 12090093: Reapply "Rename mappedBy to map." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed bug in previous commit. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/growable_array.dart ('k') | samples/swarm/DataSource.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:async'; 5 import 'dart:async';
6 import 'dart:html'; 6 import 'dart:html';
7 import 'dart:json' as jsonlib; 7 import 'dart:json' as jsonlib;
8 8
9 /// Issue wraps JSON structure that describes a bug. 9 /// Issue wraps JSON structure that describes a bug.
10 class Issue { 10 class Issue {
11 final json; 11 final json;
12 Issue(this.json); 12 Issue(this.json);
13 13
14 void addTo(Element div) { 14 void addTo(Element div) {
15 div.children.add(new Element.tag("h2")..text = json[r"title"][r"$t"]); 15 div.children.add(new Element.tag("h2")..text = json[r"title"][r"$t"]);
16 div.children.add(new Element.tag("pre")..text = json[r"content"][r"$t"]); 16 div.children.add(new Element.tag("pre")..text = json[r"content"][r"$t"]);
17 } 17 }
18 } 18 }
19 19
20 /// Decodes JSON into a list of Issues. 20 /// Decodes JSON into a list of Issues.
21 List<Issue> getIssues(json) { 21 List<Issue> getIssues(json) {
22 var issues = json["feed"]["entry"]; 22 var issues = json["feed"]["entry"];
23 if (issues == null) return null; 23 if (issues == null) return null;
24 return issues.mappedBy((data) => new Issue(data)).toList(); 24 return issues.map((data) => new Issue(data)).toList();
25 } 25 }
26 26
27 /// Iterates over the recieved issues and construct HTML for them. 27 /// Iterates over the recieved issues and construct HTML for them.
28 void processJson(json) { 28 void processJson(json) {
29 Element div = query("#content"); 29 Element div = query("#content");
30 List<Issue> list = getIssues(json); 30 List<Issue> list = getIssues(json);
31 if (list == null) { 31 if (list == null) {
32 div.children.add(new Element.tag("h2")..text = "... no issues found."); 32 div.children.add(new Element.tag("h2")..text = "... no issues found.");
33 } else { 33 } else {
34 getIssues(json).forEach((Issue i) => i.addTo(div)); 34 getIssues(json).forEach((Issue i) => i.addTo(div));
(...skipping 11 matching lines...) Expand all
46 new HttpRequest.get(url, callback); 46 new HttpRequest.get(url, callback);
47 return c.future; 47 return c.future;
48 } 48 }
49 49
50 void main() { 50 void main() {
51 // Requests new issues from the Dart issue database as json. 51 // Requests new issues from the Dart issue database as json.
52 const String url = "https://code.google.com/feeds/issues/p/dart/issues/full"; 52 const String url = "https://code.google.com/feeds/issues/p/dart/issues/full";
53 const String options = "alt=json&can=new"; 53 const String options = "alt=json&can=new";
54 requestJson("$url?$options").then(processJson); 54 requestJson("$url?$options").then(processJson);
55 } 55 }
OLDNEW
« no previous file with comments | « runtime/lib/growable_array.dart ('k') | samples/swarm/DataSource.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698