| OLD | NEW |
| (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> | |
| OLD | NEW |