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

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

Issue 23311006: Add the ability to dynamically modify transforms to barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. 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 | « no previous file | pkg/barback/lib/src/barback.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 802c8fd6f953a8671848d08eab27a65604490f40..323c83ff3d7be7773ec8d8ca04f3a5ab57e8167e 100644
--- a/pkg/barback/lib/src/asset_cascade.dart
+++ b/pkg/barback/lib/src/asset_cascade.dart
@@ -84,25 +84,9 @@ class AssetCascade {
/// Creates a new [AssetCascade].
///
- /// It loads source assets within [package] using [provider] and then uses
- /// [transformerPhases] to generate output files from them.
- //TODO(rnystrom): Better way of specifying transformers and their ordering.
- AssetCascade(this.graph, this.package,
- Iterable<Iterable<Transformer>> transformerPhases) {
- // Flatten the phases to a list so we can traverse backwards to wire up
- // each phase to its next.
- var phases = transformerPhases.toList();
- if (phases.isEmpty) phases = [[]];
-
- Phase nextPhase = null;
- for (var transformers in phases.reversed) {
- nextPhase = new Phase(this, transformers.toList(), nextPhase);
- nextPhase.onDirty.listen((_) {
- _newChanges = true;
- _waitForProcess();
- });
- _phases.insert(0, nextPhase);
- }
+ /// It loads source assets within [package] using [provider].
+ AssetCascade(this.graph, this.package) {
+ _addPhase(new Phase(this, []));
}
/// Gets the asset identified by [id].
@@ -185,11 +169,42 @@ class AssetCascade {
});
}
+ /// Sets this cascade's transformer phases to [transformers].
+ void updateTransformers(Iterable<Iterable<Transformer>> transformers) {
+ transformers = transformers.toList();
+
+ for (var i = 0; i < transformers.length; i++) {
+ if (_phases.length > i) {
+ _phases[i].updateTransformers(transformers[i]);
+ continue;
+ }
+
+ _addPhase(_phases.last.addPhase(transformers[i]));
+ }
+
+ if (transformers.length < _phases.length) {
+ for (var i = transformers.length; i < _phases.length; i++) {
+ // TODO(nweiz): actually remove phases rather than emptying them of
+ // transformers.
+ _phases[i].updateTransformers([]);
+ }
+ }
+ }
+
void reportError(BarbackException error) {
_accumulatedErrors.add(error);
_errorsController.add(error);
}
+ /// Add [phase] to the end of [_phases] and watch its [onDirty] stream.
+ void _addPhase(Phase phase) {
+ phase.onDirty.listen((_) {
+ _newChanges = true;
+ _waitForProcess();
+ });
+ _phases.add(phase);
+ }
+
/// Starts the build process asynchronously if there is work to be done.
///
/// Returns a future that completes with the background processing is done.
« no previous file with comments | « no previous file | pkg/barback/lib/src/barback.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698