mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
8260024b38
This way other scrolling demos can share the data. R=esprehn@chromium.org Review URL: https://codereview.chromium.org/876763002
47 lines
1,015 B
Plaintext
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>
|