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

Side by Side Diff: sky/examples/data/cities.sky

Issue 876763002: Move city-list data into a separate module (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « sky/examples/city-list/city-data-service.sky ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- 1 <!--
2 // Copyright 2014 The Chromium Authors. All rights reserved. 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 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 --> 5 -->
6 <script> 6 <script>
7 var cities = [ 7 module.exports = [
8 {"name":"New York","state":"New York","population":8363710}, 8 {"name":"New York","state":"New York","population":8363710},
9 {"name":"Los Angeles","state":"California","population":3833995}, 9 {"name":"Los Angeles","state":"California","population":3833995},
10 {"name":"Chicago","state":"Illinois","population":2853114}, 10 {"name":"Chicago","state":"Illinois","population":2853114},
11 {"name":"Houston","state":"Texas","population":2242193}, 11 {"name":"Houston","state":"Texas","population":2242193},
12 {"name":"Phoenix","state":"Arizona","population":1567924}, 12 {"name":"Phoenix","state":"Arizona","population":1567924},
13 {"name":"Philadelphia","state":"Pennsylvania","population":1447395}, 13 {"name":"Philadelphia","state":"Pennsylvania","population":1447395},
14 {"name":"San Antonio","state":"Texas","population":1351305}, 14 {"name":"San Antonio","state":"Texas","population":1351305},
15 {"name":"Dallas","state":"Texas","population":1279910}, 15 {"name":"Dallas","state":"Texas","population":1279910},
16 {"name":"San Diego","state":"California","population":1279329}, 16 {"name":"San Diego","state":"California","population":1279329},
17 {"name":"San Jose","state":"California","population":948279}, 17 {"name":"San Jose","state":"California","population":948279},
(...skipping 4980 matching lines...) Expand 10 before | Expand all | Expand 10 after
4998 {"name":"Chelsea","state":"Alabama","population":4303}, 4998 {"name":"Chelsea","state":"Alabama","population":4303},
4999 {"name":"Blanchester","state":"Ohio","population":4303}, 4999 {"name":"Blanchester","state":"Ohio","population":4303},
5000 {"name":"Waverly","state":"New York","population":4303}, 5000 {"name":"Waverly","state":"New York","population":4303},
5001 {"name":"Wolverine Lake","state":"Michigan","population":4303}, 5001 {"name":"Wolverine Lake","state":"Michigan","population":4303},
5002 {"name":"Jersey Shore","state":"Pennsylvania","population":4302}, 5002 {"name":"Jersey Shore","state":"Pennsylvania","population":4302},
5003 {"name":"Kenneth City","state":"Florida","population":4300}, 5003 {"name":"Kenneth City","state":"Florida","population":4300},
5004 {"name":"Jenkintown","state":"Pennsylvania","population":4299}, 5004 {"name":"Jenkintown","state":"Pennsylvania","population":4299},
5005 {"name":"Hartwell","state":"Georgia","population":4298}, 5005 {"name":"Hartwell","state":"Georgia","population":4298},
5006 {"name":"Newport","state":"North Carolina","population":4298} 5006 {"name":"Newport","state":"North Carolina","population":4298}
5007 ]; 5007 ];
5008
5009 function CityDataService(cities) {
5010 this.cities = cities;
5011
5012 // sort by state, city name.
5013 this.cities.sort(function(a, b) {
5014 if (a.state != b.state) {
5015 return a.state < b.state ? -1 : 1;
5016 }
5017
5018 return a.name < b.name ? -1 : 1;
5019 });
5020 }
5021
5022 CityDataService.prototype.get = function(index, count) {
5023 var self = this;
5024
5025 return new Promise(function(fulfill) {
5026 var result = [];
5027 while (count-- > 0) {
5028 while (index < 0) {
5029 index += self.cities.length;
5030 }
5031 if (index >= self.cities.length)
5032 index = index % self.cities.length;
5033
5034 result.push(self.cities[index]);
5035 index++;
5036 }
5037
5038 fulfill(result);
5039 });
5040 }
5041
5042 module.exports = {
5043 service: new Promise(function(fulfill) {
5044 fulfill(new CityDataService(cities));
5045 })
5046 };
5047
5048 </script> 5008 </script>
OLDNEW
« no previous file with comments | « sky/examples/city-list/city-data-service.sky ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698