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

Side by Side Diff: sky/examples/city-list/city-data-service.sky

Issue 980323003: Clean up examples directory (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « sky/examples/README.md ('k') | sky/examples/city-list/city-list.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!--
2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 -->
6 <import src="../data/cities.sky" as="cities" />
7 <script>
8 function CityDataService(cities) {
9 this.cities = cities;
10
11 // sort by state, city name.
12 this.cities.sort(function(a, b) {
13 if (a.state != b.state) {
14 return a.state < b.state ? -1 : 1;
15 }
16
17 return a.name < b.name ? -1 : 1;
18 });
19 }
20
21 CityDataService.prototype.get = function(index, count) {
22 var self = this;
23
24 return new Promise(function(fulfill) {
25 var result = [];
26 while (count-- > 0) {
27 while (index < 0) {
28 index += self.cities.length;
29 }
30 if (index >= self.cities.length)
31 index = index % self.cities.length;
32
33 result.push(self.cities[index]);
34 index++;
35 }
36
37 fulfill(result);
38 });
39 }
40
41 module.exports = {
42 service: new Promise(function(fulfill) {
43 fulfill(new CityDataService(cities));
44 })
45 };
46 </script>
OLDNEW
« no previous file with comments | « sky/examples/README.md ('k') | sky/examples/city-list/city-list.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698