提交 3f3b07ac 编写于 作者: A Adam Barth

Teach Stocks how to load data when run from a package

When run with a root bundle, the Stocks app now fetches its data from the
Internet.

R=eseidel@chromium.org, eseidel@google.com

Review URL: https://codereview.chromium.org/1208053008 .
上级 d510c25a
......@@ -6,6 +6,7 @@ import 'dart:convert';
import 'dart:math';
import 'package:sky/mojo/net/fetch.dart';
import 'package:sky/mojo/asset_bundle.dart';
// Snapshot from http://www.nasdaq.com/screening/company-list.aspx
// Fetched 2/23/2014.
......@@ -51,6 +52,12 @@ class StockData {
typedef void StockDataCallback(StockData data);
const _kChunkCount = 30;
String _urlToFetch(int chunk) {
if (rootBundle == null)
return '../data/stock_data_${chunk}.json';
return 'https://domokit.github.io/example/stocks/data/stock_data_${chunk}.json';
}
class StockDataFetcher {
int _currentChunk = 0;
final StockDataCallback callback;
......@@ -60,7 +67,7 @@ class StockDataFetcher {
}
void _fetchNextChunk() {
fetchBody('../data/stock_data_${_currentChunk++}.json').then((Response response) {
fetchBody(_urlToFetch(_currentChunk++)).then((Response response) {
String json = response.bodyAsString();
JsonDecoder decoder = new JsonDecoder();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册