| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library barback.transformer.declaring_aggregate_transform; | 5 library barback.transformer.declaring_aggregate_transform; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import '../asset/asset_id.dart'; | 9 import '../asset/asset_id.dart'; |
| 10 import '../graph/transform_node.dart'; | 10 import '../graph/transform_node.dart'; |
| 11 import '../utils.dart'; | 11 import '../utils.dart'; |
| 12 import 'base_transform.dart'; | 12 import 'base_transform.dart'; |
| 13 | 13 |
| 14 /// A transform for [DeclaringAggregateTransformer]s that allows them to declare | 14 /// A transform for [DeclaringAggregateTransformer]s that allows them to declare |
| 15 /// the ids of the outputs they'll generate without generating the concrete | 15 /// the ids of the outputs they'll generate without generating the concrete |
| 16 /// bodies of those outputs. | 16 /// bodies of those outputs. |
| 17 class DeclaringAggregateTransform extends BaseTransform { | 17 class DeclaringAggregateTransform extends BaseTransform { |
| 18 /// The set of output ids declared by the transformer. | 18 /// The set of output ids declared by the transformer. |
| 19 final _outputIds = new Set<AssetId>(); | 19 final _outputIds = new Set<AssetId>(); |
| 20 | 20 |
| 21 /// The transform key. | 21 /// The transform key. |
| 22 /// | 22 /// |
| 23 /// This is the key returned by [AggregateTransformer.classifyPrimary] for all | 23 /// This is the key returned by [AggregateTransformer.classifyPrimary] for all |
| 24 /// the assets in this transform. | 24 /// the assets in this transform. |
| 25 final String key; | 25 final String key; |
| 26 | 26 |
| 27 /// The package in which this transform is running. |
| 28 final String package; |
| 29 |
| 27 /// The stream of primary input ids that have been aggregated for this | 30 /// The stream of primary input ids that have been aggregated for this |
| 28 /// transform. | 31 /// transform. |
| 29 /// | 32 /// |
| 30 /// This is exposed as a stream so that the transformer can start working | 33 /// This is exposed as a stream so that the transformer can start working |
| 31 /// before all its input ids are available. The stream is closed not just when | 34 /// before all its input ids are available. The stream is closed not just when |
| 32 /// all inputs are provided, but when barback is confident no more inputs will | 35 /// all inputs are provided, but when barback is confident no more inputs will |
| 33 /// be forthcoming. | 36 /// be forthcoming. |
| 34 /// | 37 /// |
| 35 /// A transformer may complete its `declareOutputs` method before this stream | 38 /// A transformer may complete its `declareOutputs` method before this stream |
| 36 /// is closed. For example, it may know that each key will only have two | 39 /// is closed. For example, it may know that each key will only have two |
| 37 /// inputs associated with it, and so use `transform.primaryIds.take(2)` to | 40 /// inputs associated with it, and so use `transform.primaryIds.take(2)` to |
| 38 /// access only those inputs' ids. | 41 /// access only those inputs' ids. |
| 39 Stream<AssetId> get primaryIds => _primaryIds; | 42 Stream<AssetId> get primaryIds => _primaryIds; |
| 40 Stream<AssetId> _primaryIds; | 43 Stream<AssetId> _primaryIds; |
| 41 | 44 |
| 42 /// The controller for [primaryIds]. | 45 /// The controller for [primaryIds]. |
| 43 /// | 46 /// |
| 44 /// This is a broadcast controller so that the transform can keep | 47 /// This is a broadcast controller so that the transform can keep |
| 45 /// [_emittedPrimaryIds] up to date. | 48 /// [_emittedPrimaryIds] up to date. |
| 46 final _idController = new StreamController<AssetId>.broadcast(); | 49 final _idController = new StreamController<AssetId>.broadcast(); |
| 47 | 50 |
| 48 /// The set of all primary input ids that have been emitted by [primaryIds]. | 51 /// The set of all primary input ids that have been emitted by [primaryIds]. |
| 49 final _emittedPrimaryIds = new Set<AssetId>(); | 52 final _emittedPrimaryIds = new Set<AssetId>(); |
| 50 | 53 |
| 51 DeclaringAggregateTransform._(TransformNode node) | 54 DeclaringAggregateTransform._(TransformNode node) |
| 52 : key = node.key, | 55 : key = node.key, |
| 56 package = node.phase.cascade.package, |
| 53 super(node) { | 57 super(node) { |
| 54 _idController.stream.listen(_emittedPrimaryIds.add); | 58 _idController.stream.listen(_emittedPrimaryIds.add); |
| 55 // [primaryIds] should be a non-broadcast stream. | 59 // [primaryIds] should be a non-broadcast stream. |
| 56 _primaryIds = broadcastToSingleSubscription(_idController.stream); | 60 _primaryIds = broadcastToSingleSubscription(_idController.stream); |
| 57 } | 61 } |
| 58 | 62 |
| 59 /// Stores [id] as the id of an output that will be created by this | 63 /// Stores [id] as the id of an output that will be created by this |
| 60 /// transformation when it's run. | 64 /// transformation when it's run. |
| 61 /// | 65 /// |
| 62 /// A transformation can declare as many assets as it wants. If | 66 /// A transformation can declare as many assets as it wants. If |
| (...skipping 29 matching lines...) Expand all Loading... |
| 92 : super(new DeclaringAggregateTransform._(node)); | 96 : super(new DeclaringAggregateTransform._(node)); |
| 93 | 97 |
| 94 /// Adds a primary input id to the [DeclaringAggregateTransform.primaryIds] | 98 /// Adds a primary input id to the [DeclaringAggregateTransform.primaryIds] |
| 95 /// stream. | 99 /// stream. |
| 96 void addId(AssetId id) => transform._idController.add(id); | 100 void addId(AssetId id) => transform._idController.add(id); |
| 97 | 101 |
| 98 void done() { | 102 void done() { |
| 99 transform._idController.close(); | 103 transform._idController.close(); |
| 100 } | 104 } |
| 101 } | 105 } |
| OLD | NEW |