| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library barback.transformer.declaring_transform; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import '../asset/asset_id.dart'; | |
| 10 import 'declaring_aggregate_transform.dart'; | |
| 11 import 'transform_logger.dart'; | |
| 12 | |
| 13 /// Creates a new [DeclaringTransform] wrapping an | |
| 14 /// [AggregateDeclaringTransform]. | |
| 15 /// | |
| 16 /// Although barback internally works in terms of | |
| 17 /// [DeclaringAggregateTransformer]s, most transformers only work on individual | |
| 18 /// primary inputs in isolation. We want to allow those transformers to | |
| 19 /// implement the more user-friendly [DeclaringTransformer] interface which | |
| 20 /// takes the more user-friendly [DeclaringTransform] object. This method wraps | |
| 21 /// the more general [DeclaringAggregateTransform] to return a | |
| 22 /// [DeclaringTransform] instead. | |
| 23 Future<DeclaringTransform> newDeclaringTransform( | |
| 24 DeclaringAggregateTransform aggregate) { | |
| 25 // A wrapped [Transformer] will assign each primary input a unique transform | |
| 26 // key, so we can safely get the first asset emitted. We don't want to wait | |
| 27 // for the stream to close, since that requires barback to prove that no more | |
| 28 // new assets will be generated. | |
| 29 return aggregate.primaryIds.first.then((primaryId) => | |
| 30 new DeclaringTransform._(aggregate, primaryId)); | |
| 31 } | |
| 32 | |
| 33 /// A transform for [DeclaringTransformer]s that allows them to declare the ids | |
| 34 /// of the outputs they'll generate without generating the concrete bodies of | |
| 35 /// those outputs. | |
| 36 class DeclaringTransform { | |
| 37 /// The underlying aggregate transform. | |
| 38 final DeclaringAggregateTransform _aggregate; | |
| 39 | |
| 40 final AssetId primaryId; | |
| 41 | |
| 42 /// A logger so that the [Transformer] can report build details. | |
| 43 TransformLogger get logger => _aggregate.logger; | |
| 44 | |
| 45 DeclaringTransform._(this._aggregate, this.primaryId); | |
| 46 | |
| 47 /// Stores [id] as the id of an output that will be created by this | |
| 48 /// transformation when it's run. | |
| 49 /// | |
| 50 /// A transformation can declare as many assets as it wants. If | |
| 51 /// [DeclaringTransformer.declareOutputs] declareds a given asset id for a | |
| 52 /// given input, [Transformer.apply] should emit the corresponding asset as | |
| 53 /// well. | |
| 54 void declareOutput(AssetId id) => _aggregate.declareOutput(id); | |
| 55 | |
| 56 /// Consume the primary input so that it doesn't get processed by future | |
| 57 /// phases or emitted once processing has finished. | |
| 58 /// | |
| 59 /// Normally the primary input will automatically be forwarded unless the | |
| 60 /// transformer overwrites it by emitting an input with the same id. This | |
| 61 /// allows the transformer to tell barback not to forward the primary input | |
| 62 /// even if it's not overwritten. | |
| 63 void consumePrimary() => _aggregate.consumePrimary(primaryId); | |
| 64 } | |
| OLD | NEW |