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

Unified Diff: pkg/barback/lib/src/phase.dart

Issue 22854022: Remove the transformless phase from AssetCascade. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/barback/lib/src/asset_cascade.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/phase.dart
diff --git a/pkg/barback/lib/src/phase.dart b/pkg/barback/lib/src/phase.dart
index 86444add475c03b5d492093068f3fd9fdbbdfb72..983b32defa0ea548940c9f8ae46e414a2cbf1982 100644
--- a/pkg/barback/lib/src/phase.dart
+++ b/pkg/barback/lib/src/phase.dart
@@ -34,9 +34,6 @@ class Phase {
/// The cascade that owns this phase.
final AssetCascade cascade;
- /// This phase's position relative to the other phases. Zero-based.
- final int _index;
-
/// The transformers that can access [inputs].
///
/// Their outputs will be available to the next phase.
@@ -108,7 +105,7 @@ class Phase {
/// Outputs from this phase will be passed to it.
final Phase _next;
- Phase(this.cascade, this._index, this._transformers, this._next) {
+ Phase(this.cascade, this._transformers, this._next) {
_onDirtyPool.add(_onDirtyController.stream);
}
@@ -180,6 +177,25 @@ class Phase {
});
}
+ /// Gets the asset node for an output [id].
+ ///
+ /// If an output with that ID cannot be found, returns null.
+ Future<AssetNode> getOutput(AssetId id) {
+ return newFuture(() {
+ if (id.package != cascade.package) return cascade.graph.getAssetNode(id);
+ if (!_outputs.containsKey(id)) return null;
+ return _outputs[id].first;
+ });
+ }
+
+ /// Returns all currently-available output assets for this phase.
+ AssetSet get availableOutputs {
+ return new AssetSet.from(_outputs.values
+ .map((queue) => queue.first)
+ .where((node) => node.state.isAvailable)
+ .map((node) => node.asset));
+ }
Bob Nystrom 2013/08/19 20:46:36 Nit, but I think we generally put getters above th
nweiz 2013/08/20 00:26:26 Done.
+
/// Asynchronously determines which transformers can consume [node] as a
/// primary input and creates transforms for them.
///
@@ -323,8 +339,6 @@ class Phase {
/// Applies all currently wired up and dirty transforms.
Future _processTransforms() {
- if (_next == null) return;
-
var newPassThroughs = _passThroughControllers.values
.map((controller) => controller.node)
.where((output) {
@@ -340,19 +354,15 @@ class Phase {
if (dirtyTransforms.isEmpty && newPassThroughs.isEmpty) return null;
- var collisions = _passAssetsThrough(newPassThroughs);
+ var collisions = new Set<AssetId>();
+ for (var output in newPassThroughs) {
+ if (_addOutput(output)) collisions.add(output.id);
+ }
+
return Future.wait(dirtyTransforms.map((transform) {
return transform.apply().then((outputs) {
for (var output in outputs) {
- if (_outputs.containsKey(output.id)) {
- _outputs[output.id].add(output);
- collisions.add(output.id);
- } else {
- _outputs[output.id] = new Queue<AssetNode>.from([output]);
- _next.addInput(output);
- }
-
- _handleOutputRemoval(output);
+ if (_addOutput(output)) collisions.add(output.id);
}
});
})).then((_) {
@@ -371,28 +381,21 @@ class Phase {
});
}
- /// Pass all new assets that aren't consumed by transforms through to the next
- /// phase.
+ /// Add [output] as an output of this phase, forwarding it to the next phase
+ /// if necessary.
///
- /// Returns a set of asset ids that have collisions between new passed-through
- /// assets and pre-existing transform outputs.
- Set<AssetId> _passAssetsThrough(Set<AssetId> newPassThroughs) {
- var collisions = new Set<AssetId>();
- for (var output in newPassThroughs) {
- if (_outputs.containsKey(output.id)) {
- // There shouldn't be another pass-through asset with the same id.
- assert(!_outputs[output.id].any((asset) => asset.transform == null));
+ /// Returns whether or not [output] collides with another pre-existing output.
+ bool _addOutput(AssetNode output) {
+ _handleOutputRemoval(output);
- _outputs[output.id].add(output);
- collisions.add(output.id);
- } else {
- _outputs[output.id] = new Queue<AssetNode>.from([output]);
- _next.addInput(output);
- }
-
- _handleOutputRemoval(output);
+ if (_outputs.containsKey(output.id)) {
+ _outputs[output.id].add(output);
+ return true;
}
- return collisions;
+
+ _outputs[output.id] = new Queue<AssetNode>.from([output]);
+ if (_next != null) _next.addInput(output);
+ return false;
}
/// Properly resolve collisions when [output] is removed.
@@ -414,7 +417,7 @@ class Phase {
// (chronologically) to the next phase. Pump the event queue first to give
// [_next] a chance to handle the removal of its input before getting a
// new input.
- if (wasFirst) {
+ if (wasFirst && _next != null) {
newFuture(() => _next.addInput(assets.first));
}
« no previous file with comments | « pkg/barback/lib/src/asset_cascade.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698