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

Unified Diff: pkg/barback/lib/src/transformer/declaring_transform.dart

Issue 262173009: Add aggregate transformer types to barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 7 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/transformer/declaring_transform.dart
diff --git a/pkg/barback/lib/src/transformer/declaring_transform.dart b/pkg/barback/lib/src/transformer/declaring_transform.dart
index e15082fc37ad6d33310bf029315385e20fab4c71..7dff33a83d51f74dec2f4608ba4b25b9ae3dc97e 100644
--- a/pkg/barback/lib/src/transformer/declaring_transform.dart
+++ b/pkg/barback/lib/src/transformer/declaring_transform.dart
@@ -4,21 +4,45 @@
library barback.transformer.declaring_transform;
+import 'dart:async';
+
import '../asset/asset_id.dart';
-import '../graph/transform_node.dart';
-import 'base_transform.dart';
+import 'declaring_aggregate_transform.dart';
+import 'transform_logger.dart';
+
+/// Creates a new [DeclaringTransform] wrapping an
+/// [AggregateDeclaringTransform].
+///
+/// Although barback internally works in terms of
+/// [DeclaringAggregateTransformer]s, most transformers only work on individual
+/// primary inputs in isolation. We want to allow those transformers to
+/// implement the more user-friendly [DeclaringTransformer] interface which
+/// takes the more user-friendly [DeclaringTransform] object. This method wraps
+/// the more general [DeclaringAggregateTransform] to return a
+/// [DeclaringTransform] instead.
+Future<DeclaringTransform> newDeclaringTransform(
+ DeclaringAggregateTransform aggregate) {
+ // A wrapped [Transformer] will assign each primary input a unique transform
+ // key, so we can safely get the first asset emitted. We don't want to wait
+ // for the stream to close, since that requires barback to prove that no more
+ // new assets will be generated.
+ return aggregate.primaryIds.first.then((primaryId) =>
+ new DeclaringTransform._(aggregate, primaryId));
+}
-/// A transform for [DeclaringTransform]ers that allows them to declare the ids
+/// A transform for [DeclaringTransformer]s that allows them to declare the ids
/// of the outputs they'll generate without generating the concrete bodies of
/// those outputs.
-class DeclaringTransform extends BaseTransform {
- final _outputIds = new Set<AssetId>();
+class DeclaringTransform {
+ /// The underlying aggregate transform.
+ final DeclaringAggregateTransform _aggregate;
final AssetId primaryId;
- DeclaringTransform._(TransformNode node)
- : primaryId = node.primary.id,
- super(node);
+ /// A logger so that the [Transformer] can report build details.
+ TransformLogger get logger => _aggregate.logger;
+
+ DeclaringTransform._(this._aggregate, this.primaryId);
/// Stores [id] as the id of an output that will be created by this
/// transformation when it's run.
@@ -27,21 +51,14 @@ class DeclaringTransform extends BaseTransform {
/// [DeclaringTransformer.declareOutputs] declareds a given asset id for a
/// given input, [Transformer.apply] should emit the corresponding asset as
/// well.
- void declareOutput(AssetId id) {
- // TODO(nweiz): This should immediately throw if an output with that ID
- // has already been declared by this transformer.
- _outputIds.add(id);
- }
-}
-
-/// The controller for [DeclaringTransform].
-class DeclaringTransformController extends BaseTransformController {
- DeclaringTransform get transform => super.transform;
+ void declareOutput(AssetId id) => _aggregate.declareOutput(id);
- /// The set of ids that the transformer declares it will emit for the given
- /// primary input.
- Set<AssetId> get outputIds => transform._outputIds;
-
- DeclaringTransformController(TransformNode node)
- : super(new DeclaringTransform._(node));
+ /// Consume the primary input so that it doesn't get processed by future
+ /// phases or emitted once processing has finished.
+ ///
+ /// Normally the primary input will automatically be forwarded unless the
+ /// transformer overwrites it by emitting an input with the same id. This
+ /// allows the transformer to tell barback not to forward the primary input
+ /// even if it's not overwritten.
+ void consumePrimary() => _aggregate.consumePrimary(primaryId);
}

Powered by Google App Engine
This is Rietveld 408576698