| <!-- |
| // Copyright 2014 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| --> |
| <import src="../data/cities.sky" as="cities" /> |
| <script> |
| function CityDataService(cities) { |
| this.cities = cities; |
| |
| // sort by state, city name. |
| this.cities.sort(function(a, b) { |
| if (a.state != b.state) { |
| return a.state < b.state ? -1 : 1; |
| } |
| |
| return a.name < b.name ? -1 : 1; |
| }); |
| } |
| |
| CityDataService.prototype.get = function(index, count) { |
| var self = this; |
| |
| return new Promise(function(fulfill) { |
| var result = []; |
| while (count-- > 0) { |
| while (index < 0) { |
| index += self.cities.length; |
| } |
| if (index >= self.cities.length) |
| index = index % self.cities.length; |
| |
| result.push(self.cities[index]); |
| index++; |
| } |
| |
| fulfill(result); |
| }); |
| } |
| |
| module.exports = { |
| service: new Promise(function(fulfill) { |
| fulfill(new CityDataService(cities)); |
| }) |
| }; |
| </script> |