| 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; | 5 library barback.phase; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'asset_cascade.dart'; | 9 import 'asset_cascade.dart'; |
| 10 import 'asset_id.dart'; | 10 import 'asset_id.dart'; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 /// will automatically begin determining which transforms can consume it as a | 129 /// will automatically begin determining which transforms can consume it as a |
| 130 /// primary input. The transforms themselves won't be applied until [process] | 130 /// primary input. The transforms themselves won't be applied until [process] |
| 131 /// is called, however. | 131 /// is called, however. |
| 132 /// | 132 /// |
| 133 /// This should only be used for brand-new assets or assets that have been | 133 /// This should only be used for brand-new assets or assets that have been |
| 134 /// removed and re-created. The phase will automatically handle updated assets | 134 /// removed and re-created. The phase will automatically handle updated assets |
| 135 /// using the [AssetNode.onStateChange] stream. | 135 /// using the [AssetNode.onStateChange] stream. |
| 136 void addInput(AssetNode node) { | 136 void addInput(AssetNode node) { |
| 137 if (_inputs.containsKey(node.id)) _inputs[node.id].remove(); | 137 if (_inputs.containsKey(node.id)) _inputs[node.id].remove(); |
| 138 | 138 |
| 139 node.force(); |
| 140 |
| 139 // Each group is one channel along which an asset may be forwarded. Then | 141 // Each group is one channel along which an asset may be forwarded. Then |
| 140 // there's one additional channel for the non-grouped transformers. | 142 // there's one additional channel for the non-grouped transformers. |
| 141 var forwarder = new PhaseForwarder(_groups.length + 1); | 143 var forwarder = new PhaseForwarder(_groups.length + 1); |
| 142 _forwarders[node.id] = forwarder; | 144 _forwarders[node.id] = forwarder; |
| 143 forwarder.onForwarding.listen((asset) { | 145 forwarder.onForwarding.listen((asset) { |
| 144 _addOutput(asset); | 146 _addOutput(asset); |
| 145 | 147 |
| 146 var exception = _outputs[asset.id].collisionException; | 148 var exception = _outputs[asset.id].collisionException; |
| 147 if (exception != null) cascade.reportError(exception); | 149 if (exception != null) cascade.reportError(exception); |
| 148 }); | 150 }); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 175 }); | 177 }); |
| 176 } | 178 } |
| 177 | 179 |
| 178 /// Gets the asset node for an output [id]. | 180 /// Gets the asset node for an output [id]. |
| 179 /// | 181 /// |
| 180 /// If an output with that ID cannot be found, returns null. | 182 /// If an output with that ID cannot be found, returns null. |
| 181 Future<AssetNode> getOutput(AssetId id) { | 183 Future<AssetNode> getOutput(AssetId id) { |
| 182 return newFuture(() { | 184 return newFuture(() { |
| 183 if (id.package != cascade.package) return cascade.graph.getAssetNode(id); | 185 if (id.package != cascade.package) return cascade.graph.getAssetNode(id); |
| 184 if (!_outputs.containsKey(id)) return null; | 186 if (!_outputs.containsKey(id)) return null; |
| 185 return _outputs[id].output; | 187 var output = _outputs[id].output; |
| 188 output.force(); |
| 189 return output; |
| 186 }); | 190 }); |
| 187 } | 191 } |
| 188 | 192 |
| 189 /// Set this phase's transformers to [transformers]. | 193 /// Set this phase's transformers to [transformers]. |
| 190 void updateTransformers(Iterable transformers) { | 194 void updateTransformers(Iterable transformers) { |
| 191 _onDirtyController.add(null); | 195 _onDirtyController.add(null); |
| 192 | 196 |
| 193 var actualTransformers = transformers.where((op) => op is Transformer); | 197 var actualTransformers = transformers.where((op) => op is Transformer); |
| 194 _transformers.clear(); | 198 _transformers.clear(); |
| 195 _transformers.addAll(actualTransformers); | 199 _transformers.addAll(actualTransformers); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 212 for (var input in _inputs.values) { | 216 for (var input in _inputs.values) { |
| 213 runner.addInput(input.input); | 217 runner.addInput(input.input); |
| 214 } | 218 } |
| 215 } | 219 } |
| 216 | 220 |
| 217 for (var forwarder in _forwarders.values) { | 221 for (var forwarder in _forwarders.values) { |
| 218 forwarder.numChannels = _groups.length + 1; | 222 forwarder.numChannels = _groups.length + 1; |
| 219 } | 223 } |
| 220 } | 224 } |
| 221 | 225 |
| 226 /// Force all [LazyTransformer]s' transforms in this phase to begin producing |
| 227 /// concrete assets. |
| 228 void forceAllTransforms() { |
| 229 for (var group in _groups.values) { |
| 230 group.forceAllTransforms(); |
| 231 } |
| 232 |
| 233 for (var input in _inputs.values) { |
| 234 input.forceAllTransforms(); |
| 235 } |
| 236 } |
| 237 |
| 222 /// Add a new phase after this one with [transformers]. | 238 /// Add a new phase after this one with [transformers]. |
| 223 /// | 239 /// |
| 224 /// This may only be called on a phase with no phase following it. | 240 /// This may only be called on a phase with no phase following it. |
| 225 Phase addPhase(Iterable transformers) { | 241 Phase addPhase(Iterable transformers) { |
| 226 assert(_next == null); | 242 assert(_next == null); |
| 227 _next = new Phase(cascade, transformers); | 243 _next = new Phase(cascade, transformers); |
| 228 for (var output in _outputs.values.toList()) { | 244 for (var output in _outputs.values.toList()) { |
| 229 // Remove [output]'s listeners because now they should get the asset from | 245 // Remove [output]'s listeners because now they should get the asset from |
| 230 // [_next], rather than this phase. Any transforms consuming [output] will | 246 // [_next], rather than this phase. Any transforms consuming [output] will |
| 231 // be re-run and will consume the output from the new final phase. | 247 // be re-run and will consume the output from the new final phase. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 _outputs[asset.id].add(asset); | 322 _outputs[asset.id].add(asset); |
| 307 } else { | 323 } else { |
| 308 _outputs[asset.id] = new PhaseOutput(this, asset); | 324 _outputs[asset.id] = new PhaseOutput(this, asset); |
| 309 _outputs[asset.id].onAsset.listen((output) { | 325 _outputs[asset.id].onAsset.listen((output) { |
| 310 if (_next != null) _next.addInput(output); | 326 if (_next != null) _next.addInput(output); |
| 311 }, onDone: () => _outputs.remove(asset.id)); | 327 }, onDone: () => _outputs.remove(asset.id)); |
| 312 if (_next != null) _next.addInput(_outputs[asset.id].output); | 328 if (_next != null) _next.addInput(_outputs[asset.id].output); |
| 313 } | 329 } |
| 314 } | 330 } |
| 315 } | 331 } |
| OLD | NEW |