| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.phase_output; | 5 library barback.phase_output; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'asset_cascade.dart'; | |
| 11 import 'asset_forwarder.dart'; | 10 import 'asset_forwarder.dart'; |
| 12 import 'asset_node.dart'; | 11 import 'asset_node.dart'; |
| 13 import 'errors.dart'; | 12 import 'errors.dart'; |
| 14 import 'phase.dart'; | 13 import 'phase.dart'; |
| 15 import 'utils.dart'; | |
| 16 | 14 |
| 17 /// A class that handles a single output of a phase. | 15 /// A class that handles a single output of a phase. |
| 18 /// | 16 /// |
| 19 /// Normally there's only a single [AssetNode] for a phase's output, but it's | 17 /// Normally there's only a single [AssetNode] for a phase's output, but it's |
| 20 /// possible that multiple transformers in the same phase emit assets with the | 18 /// possible that multiple transformers in the same phase emit assets with the |
| 21 /// same id, causing collisions. This handles those collisions by forwarding the | 19 /// same id, causing collisions. This handles those collisions by forwarding the |
| 22 /// chronologically first asset. | 20 /// chronologically first asset. |
| 23 /// | 21 /// |
| 24 /// When the asset being forwarding changes, the old value of [output] will be | 22 /// When the asset being forwarding changes, the old value of [output] will be |
| 25 /// marked as removed and a new value will replace it. Users of this class can | 23 /// marked as removed and a new value will replace it. Users of this class can |
| 26 /// be notified of this using [onAsset]. | 24 /// be notified of this using [onAsset]. |
| 27 class PhaseOutput { | 25 class PhaseOutput { |
| 28 /// The phase for which this is an output. | 26 /// The phase for which this is an output. |
| 29 final Phase _phase; | 27 final Phase _phase; |
| 30 | 28 |
| 31 /// A string describing the location of [this] in the transformer graph. | 29 /// A string describing the location of [this] in the transformer graph. |
| 32 final String _location; | 30 final String _location; |
| 33 | 31 |
| 34 /// The asset node for this output. | 32 /// The asset node for this output. |
| 35 AssetNode get output => _outputForwarder.node; | 33 AssetNode get output => _outputForwarder.node; |
| 36 AssetForwarder _outputForwarder; | 34 AssetForwarder _outputForwarder; |
| 37 | 35 |
| 38 /// A stream that emits an [AssetNode] each time this output starts forwarding | 36 /// A stream that emits an [AssetNode] each time this output starts forwarding |
| 39 /// a new asset. | 37 /// a new asset. |
| 40 Stream<AssetNode> get onAsset => _onAssetController.stream; | 38 Stream<AssetNode> get onAsset => _onAssetController.stream; |
| 41 final _onAssetController = new StreamController<AssetNode>(); | 39 final _onAssetController = new StreamController<AssetNode>(sync: true); |
| 42 | 40 |
| 43 /// The assets for this output. | 41 /// The assets for this output. |
| 44 /// | 42 /// |
| 45 /// If there's no collision, this will only have one element. Otherwise, it | 43 /// If there's no collision, this will only have one element. Otherwise, it |
| 46 /// will be ordered by which asset was added first. | 44 /// will be ordered by which asset was added first. |
| 47 final _assets = new Queue<AssetNode>(); | 45 final _assets = new Queue<AssetNode>(); |
| 48 | 46 |
| 49 /// The [AssetCollisionException] for this output, or null if there is no | 47 /// The [AssetCollisionException] for this output, or null if there is no |
| 50 /// collision currently. | 48 /// collision currently. |
| 51 AssetCollisionException get collisionException { | 49 AssetCollisionException get collisionException { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 var wasFirst = _assets.first == node; | 96 var wasFirst = _assets.first == node; |
| 99 _assets.remove(node); | 97 _assets.remove(node); |
| 100 | 98 |
| 101 // If this was the first asset, we replace it with the next asset | 99 // If this was the first asset, we replace it with the next asset |
| 102 // (chronologically). | 100 // (chronologically). |
| 103 if (wasFirst) removeListeners(); | 101 if (wasFirst) removeListeners(); |
| 104 | 102 |
| 105 // If there's still a collision, report it. This lets the user know if | 103 // If there's still a collision, report it. This lets the user know if |
| 106 // they've successfully resolved the collision or not. | 104 // they've successfully resolved the collision or not. |
| 107 if (_assets.length > 1) { | 105 if (_assets.length > 1) { |
| 108 // Pump the event queue to ensure that the removal of the input triggers | |
| 109 // a new build to which we can attach the error. | |
| 110 // TODO(nweiz): report this through the output asset. | 106 // TODO(nweiz): report this through the output asset. |
| 111 newFuture(() => _phase.cascade.reportError(collisionException)); | 107 _phase.cascade.reportError(collisionException); |
| 112 } | 108 } |
| 113 }); | 109 }); |
| 114 } | 110 } |
| 115 | 111 |
| 116 String toString() => "phase output in $_location for $output"; | 112 String toString() => "phase output in $_location for $output"; |
| 117 } | 113 } |
| OLD | NEW |