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

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

Issue 196273003: Move isPrimary computation from PhaseInput into TransformNode. (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/phase_forwarder.dart
diff --git a/pkg/barback/lib/src/phase_forwarder.dart b/pkg/barback/lib/src/phase_forwarder.dart
index 1d5682d9f3542f09a2f6695808c8767a6c51621c..85def2379d1f271e29a10b4ee356d32a4632c691 100644
--- a/pkg/barback/lib/src/phase_forwarder.dart
+++ b/pkg/barback/lib/src/phase_forwarder.dart
@@ -11,8 +11,8 @@ import 'asset_node_set.dart';
/// A class that takes care of forwarding assets within a phase.
///
-/// Each phase contains one or more channels that process its input assets. The
-/// non-grouped transformers for that phase are one such channel, and each
+/// Each phase contains one or more channels that process its input assets. Each
+/// non-grouped transformer for that phase is a channel, and each
/// [TransformerGroup] in that phase is another. For each input asset, each
/// channel individually decides whether to forward that asset based on whether
/// that channel uses it. If a channel does decide to forward an asset, we call
@@ -32,21 +32,29 @@ import 'asset_node_set.dart';
class PhaseForwarder {
/// The number of channels through which the asset may have been forwarded.
///
- /// Each group is a channel, along with one channel for the [PhaseInput] that
- /// handles all the transformers.
+ /// Each transformer in the phase is a channel, as is each group. [value] may
+ /// be zero, indicating that this phase has no transformers or groups; if so,
+ /// the asset is always forwarded.
set numChannels(int value) {
_numChannels = value;
_adjustOutput();
}
int _numChannels;
+ /// The real number of channels to forward, counting the source node.
+ ///
+ /// This is one higher than [numChannels] because the source node should get
+ /// forwarded if there are no other channels.
+ int get _realNumChannels => _numChannels + 1;
Bob Nystrom 2014/03/12 17:42:58 This is pretty gross. How about we encapsulate the
nweiz 2014/03/12 21:44:47 SGTM, done.
+
/// The intermediate forwarded assets.
final _intermediateAssets = new AssetNodeSet();
/// The final forwarded asset.
///
/// This will be null if the asset is not being forwarded.
- AssetNode get output => _outputController.node;
+ AssetNode get output =>
+ _outputController == null ? null : _outputController.node;
AssetNodeController _outputController;
/// A stream that emits an event whenever [this] starts producing a final
@@ -55,9 +63,16 @@ class PhaseForwarder {
/// Whenever this stream emits an event, the value will be identical to
/// [output].
Stream<AssetNode> get onAsset => _onAssetController.stream;
- final _onAssetController = new StreamController<AssetNode>(sync: true);
+ final _onAssetController = new StreamController<AssetNode>.broadcast(sync: true);
Bob Nystrom 2014/03/12 17:42:58 Long line.
nweiz 2014/03/12 21:44:47 Done.
- PhaseForwarder(this._numChannels);
+ /// Creates a phase forwarder forwarding nodes that come from [node] across
+ /// [numChannels] channels.
+ ///
+ /// [node] is passed in explicitly so that it can be forwarded if
+ /// [numChannels] becomes zero.
+ PhaseForwarder(AssetNode node, this._numChannels) {
+ addIntermediateAsset(node);
+ }
/// Adds an intermediate forwarded asset to [this].
///
@@ -88,13 +103,13 @@ class PhaseForwarder {
/// Adjusts [output] to ensure that it accurately reflects the current state
/// of the intermediate forwarded assets.
void _adjustOutput() {
- assert(_intermediateAssets.length <= _numChannels);
+ assert(_intermediateAssets.length <= _realNumChannels);
assert(!_intermediateAssets.any((asset) => asset.state.isRemoved));
// If there are any channels that haven't forwarded an intermediate asset,
// we shouldn't forward a final asset. If we are currently, remove
// it.
- if (_intermediateAssets.length < _numChannels) {
+ if (_intermediateAssets.length < _realNumChannels) {
if (_outputController == null) return;
_outputController.setRemoved();
_outputController = null;
@@ -116,10 +131,8 @@ class PhaseForwarder {
// intermediate assets are dirty.
if (_intermediateAssets.any((asset) => asset.state.isDirty)) {
if (!_outputController.node.state.isDirty) _outputController.setDirty();
- } else {
- if (!_outputController.node.state.isAvailable) {
- _outputController.setAvailable(_intermediateAssets.first.asset);
- }
+ } else if (!_outputController.node.state.isAvailable) {
+ _outputController.setAvailable(_intermediateAssets.first.asset);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698