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

Side by Side Diff: pkg/barback/lib/src/transform.dart

Issue 21275003: Move barback to a more event-based model. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library barback.transform; 5 library barback.transform;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'asset.dart'; 9 import 'asset.dart';
10 import 'asset_id.dart'; 10 import 'asset_id.dart';
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return newFuture(() { 60 return newFuture(() {
61 var node = _node.phase.inputs[id]; 61 var node = _node.phase.inputs[id];
62 // TODO(rnystrom): Need to handle passthrough where an asset from a 62 // TODO(rnystrom): Need to handle passthrough where an asset from a
63 // previous phase can be found. 63 // previous phase can be found.
64 64
65 // Throw if the input isn't found. This ensures the transformer's apply 65 // Throw if the input isn't found. This ensures the transformer's apply
66 // is exited. We'll then catch this and report it through the proper 66 // is exited. We'll then catch this and report it through the proper
67 // results stream. 67 // results stream.
68 if (node == null) throw new MissingInputException(id); 68 if (node == null) throw new MissingInputException(id);
69 69
70 // Keep track of which assets this transform depends on. 70 // If the asset node is found, wait until its contents are actually
71 _inputs.add(node); 71 // available before we return them.
72 return node.asset; 72 return node.whenAvailable.then((asset) {
73 _inputs.add(node);
74 return asset;
75 }).catchError((error) {
76 if (error is! AssetNotFoundException || error.id != id) throw error;
77 // If the node was removed before it could be loaded, treat it as though
78 // it never existed and throw a MissingInputException.
79 throw new MissingInputException(id);
80 });
73 }); 81 });
74 } 82 }
75 83
76 /// Stores [output] as the output created by this transformation. 84 /// Stores [output] as the output created by this transformation.
77 /// 85 ///
78 /// A transformation can output as many assets as it wants. 86 /// A transformation can output as many assets as it wants.
79 void addOutput(Asset output) { 87 void addOutput(Asset output) {
80 // TODO(rnystrom): This should immediately throw if an output with that ID 88 // TODO(rnystrom): This should immediately throw if an output with that ID
81 // has already been created by this transformer. 89 // has already been created by this transformer.
82 _outputs.add(output); 90 _outputs.add(output);
83 } 91 }
84 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698