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

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

Issue 200983002: Re-run a transform when a secondary input starts existing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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
Index: pkg/barback/lib/src/asset_cascade.dart
diff --git a/pkg/barback/lib/src/asset_cascade.dart b/pkg/barback/lib/src/asset_cascade.dart
index f0fdcb3deb1ed4ad05e6dd0d87fc815428969f76..a17a4028d09c95f46045721984b66f1e85a5579b 100644
--- a/pkg/barback/lib/src/asset_cascade.dart
+++ b/pkg/barback/lib/src/asset_cascade.dart
@@ -48,8 +48,17 @@ class AssetCascade {
/// one.
final _loadingSources = new Map<AssetId, CancelableFuture<Asset>>();
+ /// The list of phases in this cascade.
+ ///
+ /// This will always contain at least one phase, and the first phase will
+ /// never have any transformers. This ensures that every transformer can
+ /// request inputs from a previous phase.
final _phases = <Phase>[];
+ /// The subscription to the [Phase.onDone] stream of the last [Phase] in
+ /// [_phases].
+ StreamSubscription _phaseOnDoneSubscription;
+
/// A stream that emits any errors from the cascade or the transformers.
///
/// This emits errors as they're detected. If an error occurs in one part of
@@ -169,25 +178,28 @@ class AssetCascade {
void updateTransformers(Iterable<Iterable> transformersIterable) {
var transformers = transformersIterable.toList();
- for (var i = 0; i < transformers.length; i++) {
+ // Always preserve a single phase with no transformers at the beginning of
+ // the cascade so that [TransfomNode]s in the first populated phase will
Bob Nystrom 2014/03/15 01:03:55 Transfom -> Transform
+ // have something to request assets from.
+ for (var i = 1; i <= transformers.length; i++) {
Bob Nystrom 2014/03/15 01:03:55 I think it would be clearer to keep i ranging from
if (_phases.length > i) {
- _phases[i].updateTransformers(transformers[i]);
+ _phases[i].updateTransformers(transformers[i - 1]);
continue;
}
var phase = _phases.last.addPhase();
_addPhase(phase);
- phase.updateTransformers(transformers[i]);
+ phase.updateTransformers(transformers[i - 1]);
}
- if (transformers.length == 0) {
- _phases.last.updateTransformers([]);
- } else {
- for (var i = transformers.length; i < _phases.length; i++) {
- _phases[i].remove();
- }
- _phases.removeRange(transformers.length, _phases.length);
+ for (var i = transformers.length + 1; i < _phases.length; i++) {
+ _phases[i].remove();
}
+ _phases.removeRange(transformers.length + 1, _phases.length);
+
+ _phaseOnDoneSubscription.cancel();
+ _phaseOnDoneSubscription = _phases.last.onDone
+ .listen(_onDoneController.add);
}
/// Force all [LazyTransformer]s' transforms in this cascade to begin
@@ -205,9 +217,8 @@ class AssetCascade {
/// Add [phase] to the end of [_phases] and watch its streams.
void _addPhase(Phase phase) {
_onLogPool.add(phase.onLog);
- phase.onDone.listen((_) {
- if (!isDirty) _onDoneController.add(null);
- });
+ if (_phaseOnDoneSubscription != null) _phaseOnDoneSubscription.cancel();
+ _phaseOnDoneSubscription = phase.onDone.listen(_onDoneController.add);
_phases.add(phase);
}

Powered by Google App Engine
This is Rietveld 408576698