flutter/examples/city-list/city-data-service.sky
Adam Barth 8260024b38 Move city-list data into a separate module
This way other scrolling demos can share the data.

R=esprehn@chromium.org

Review URL: https://codereview.chromium.org/876763002
2015-01-26 09:41:25 -08:00

47 lines
1,015 B
Plaintext

<!--
// 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>