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

Unified Diff: packages/when/example/read_json_file.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 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 | « packages/when/example/foo.json ('k') | packages/when/lib/when.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/when/example/read_json_file.dart
diff --git a/packages/when/example/read_json_file.dart b/packages/when/example/read_json_file.dart
deleted file mode 100755
index 3092ac8108dffb176cd460b516834bf82aadb3c2..0000000000000000000000000000000000000000
--- a/packages/when/example/read_json_file.dart
+++ /dev/null
@@ -1,38 +0,0 @@
-
-library when.example.read_json_file;
-
-import 'dart:async';
-import 'dart:convert';
-import 'dart:io';
-
-import 'package:when/when.dart';
-
-/// Reads and decodes JSON from [path] asynchronously.
-///
-/// If [path] does not exist, returns the result of calling [onAbsent].
-Future readJsonFile(String path, {onAbsent()}) => _readJsonFile(
- path, onAbsent, (file) => file.exists(), (file) => file.readAsString());
-
-/// Reads and decodes JSON from [path] synchronously.
-///
-/// If [path] does not exist, returns the result of calling [onAbsent].
-readJsonFileSync(String path, {onAbsent()}) => _readJsonFile(
- path, onAbsent, (file) => file.existsSync(),
- (file) => file.readAsStringSync());
-
-_readJsonFile(String path, onAbsent(), exists(File file), read(File file)) {
- var file = new File(path);
- return when(
- () => exists(file),
- onSuccess: (doesExist) => doesExist ?
- when(() => read(file), onSuccess: JSON.decode) :
- onAbsent());
-}
-
-main() {
- var syncJson = readJsonFileSync('foo.json', onAbsent: () => {'foo': 'bar'});
- print('Sync json: $syncJson');
- readJsonFile('foo.json', onAbsent: () => {'foo': 'bar'}).then((asyncJson) {
- print('Async json: $asyncJson');
- });
-}
« no previous file with comments | « packages/when/example/foo.json ('k') | packages/when/lib/when.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698