Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Unified Diff: sky/sdk/example/stocks/lib/stock_data.dart

Issue 1208053008: Teach Stocks how to load data when run from a package (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/example/stocks/lib/stock_data.dart
diff --git a/sky/sdk/example/stocks/lib/stock_data.dart b/sky/sdk/example/stocks/lib/stock_data.dart
index 2cd9345672c9d535428efcecf79cefda3398a8c3..57d73ecd48b0443b9eec69477b7d5f687ba27af6 100644
--- a/sky/sdk/example/stocks/lib/stock_data.dart
+++ b/sky/sdk/example/stocks/lib/stock_data.dart
@@ -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();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698