OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 part of swarmlib; | 5 part of swarmlib; |
6 | 6 |
7 /** The top-level collection of all sections for a user. */ | 7 /** The top-level collection of all sections for a user. */ |
8 // TODO(jimhug): This is known as UserData in the server model. | 8 // TODO(jimhug): This is known as UserData in the server model. |
9 class Sections extends Collection<Section> { | 9 class Sections extends Collection<Section> { |
10 final List<Section> _sections; | 10 final List<Section> _sections; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 final decoder = new Decoder(data); | 49 final decoder = new Decoder(data); |
50 int nSections = decoder.readInt(); | 50 int nSections = decoder.readInt(); |
51 final sections = new List<Section>(); | 51 final sections = new List<Section>(); |
52 | 52 |
53 for (int i=0; i < nSections; i++) { | 53 for (int i=0; i < nSections; i++) { |
54 sections.add(Section.decode(decoder)); | 54 sections.add(Section.decode(decoder)); |
55 } | 55 } |
56 callback(new Sections(sections)); | 56 callback(new Sections(sections)); |
57 } | 57 } |
58 | 58 |
59 static void initializeFromUrl(void callback(Sections sections)) { | 59 static void initializeFromUrl(bool useCannedData, |
60 if (Sections.runningFromFile) { | 60 void callback(Sections sections)) { |
| 61 if (Sections.runningFromFile || useCannedData) { |
61 initializeFromData(CannedData.data['user.data'], callback); | 62 initializeFromData(CannedData.data['user.data'], callback); |
62 } else { | 63 } else { |
63 // TODO(jmesserly): display an error if we fail here! Silent failure bad. | 64 // TODO(jmesserly): display an error if we fail here! Silent failure bad. |
64 new HttpRequest.get('data/user.data', | 65 new HttpRequest.get('data/user.data', |
65 EventBatch.wrap((request) { | 66 EventBatch.wrap((request) { |
66 // TODO(jimhug): Nice response if get error back from server. | 67 // TODO(jimhug): Nice response if get error back from server. |
67 // TODO(jimhug): Might be more efficient to parse request in sections. | 68 // TODO(jimhug): Might be more efficient to parse request in sections. |
68 initializeFromData(request.responseText, callback); | 69 initializeFromData(request.responseText, callback); |
69 })); | 70 })); |
70 } | 71 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 final hasThumbnail = decoder.readBool(); | 235 final hasThumbnail = decoder.readBool(); |
235 final author = decoder.readString(); | 236 final author = decoder.readString(); |
236 final dateInSeconds = decoder.readInt(); | 237 final dateInSeconds = decoder.readInt(); |
237 final snippet = decoder.readString(); | 238 final snippet = decoder.readString(); |
238 final date = | 239 final date = |
239 new Date.fromMillisecondsSinceEpoch(dateInSeconds*1000, isUtc: true); | 240 new Date.fromMillisecondsSinceEpoch(dateInSeconds*1000, isUtc: true); |
240 return new Article(source, id, date, title, author, srcUrl, hasThumbnail, | 241 return new Article(source, id, date, title, author, srcUrl, hasThumbnail, |
241 snippet); | 242 snippet); |
242 } | 243 } |
243 } | 244 } |
OLD | NEW |