| 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_input; | 5 library barback.phase_input; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'asset_forwarder.dart'; | 9 import 'asset_forwarder.dart'; |
| 10 import 'asset_node.dart'; | 10 import 'asset_node.dart'; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 }); | 253 }); |
| 254 | 254 |
| 255 transform.onAsset.listen((asset) { | 255 transform.onAsset.listen((asset) { |
| 256 if (asset.id == input.id) { | 256 if (asset.id == input.id) { |
| 257 _overwritingOutputs.add(asset); | 257 _overwritingOutputs.add(asset); |
| 258 asset.whenRemoved(_adjustPassThrough); | 258 asset.whenRemoved(_adjustPassThrough); |
| 259 _adjustPassThrough(); | 259 _adjustPassThrough(); |
| 260 } | 260 } |
| 261 | 261 |
| 262 _onAssetController.add(asset); | 262 _onAssetController.add(asset); |
| 263 }, onDone: () => _transforms.remove(transform)); | 263 }, onDone: () { |
| 264 _transforms.remove(transform); |
| 265 // When a transform is removed, we need to re-adjust the pass-through |
| 266 // in case its call to `consumePrimary` was preventing pass-through |
| 267 _adjustPassThrough(); |
| 268 }); |
| 264 | 269 |
| 265 _onLogPool.add(transform.onLog); | 270 _onLogPool.add(transform.onLog); |
| 266 }); | 271 }); |
| 267 })); | 272 })); |
| 268 } | 273 } |
| 269 | 274 |
| 270 /// Adjust whether [input] is passed through the phase unmodified, based on | 275 /// Adjust whether [input] is passed through the phase unmodified, based on |
| 271 /// whether it's overwritten by other transforms in this phase. | 276 /// whether it's overwritten by other transforms in this phase. |
| 272 /// | 277 /// |
| 273 /// If [input] was already passed-through, this will update the passed-through | 278 /// If [input] was already passed-through, this will update the passed-through |
| 274 /// value. | 279 /// value. |
| 275 void _adjustPassThrough() { | 280 void _adjustPassThrough() { |
| 276 // If [input] is removed, [_adjustPassThrough] can still be called due to | 281 // If [input] is removed, [_adjustPassThrough] can still be called due to |
| 277 // [TransformNode]s marking their outputs as removed. | 282 // [TransformNode]s marking their outputs as removed. |
| 278 if (!input.state.isAvailable) return; | 283 if (!input.state.isAvailable) return; |
| 279 | 284 |
| 280 // If there's an output with the same id as the primary input, that | 285 // If there's an output with the same id as the primary input, that |
| 281 // overwrites the input so it doesn't get passed through. Otherwise, | 286 // overwrites the input so it doesn't get passed through. A transformer |
| 282 // create a pass-through controller if none exists, or set the existing | 287 // explicitly consuming the input will also cause it not to get passed |
| 283 // one available. | 288 // through. Otherwise, create a pass-through controller if none exists, or |
| 284 if (_overwritingOutputs.isNotEmpty) { | 289 // set the existing one available. |
| 290 if (_overwritingOutputs.isNotEmpty || |
| 291 _transforms.any((transform) => transform.consumePrimary)) { |
| 285 if (_passThroughController != null) { | 292 if (_passThroughController != null) { |
| 286 _passThroughController.setRemoved(); | 293 _passThroughController.setRemoved(); |
| 287 _passThroughController = null; | 294 _passThroughController = null; |
| 288 } | 295 } |
| 289 } else if (isDirty) { | 296 } else if (isDirty) { |
| 290 // If the input is dirty, we're still figuring out whether a transform | 297 // If the input is dirty, we're still figuring out whether a transform |
| 291 // will overwrite the input. As such, we shouldn't pass through the asset | 298 // will overwrite the input. As such, we shouldn't pass through the asset |
| 292 // yet. | 299 // yet. |
| 293 } else if (_passThroughController == null) { | 300 } else if (_passThroughController == null) { |
| 294 _passThroughController = new AssetNodeController.from(input); | 301 _passThroughController = new AssetNodeController.from(input); |
| 295 _onAssetController.add(_passThroughController.node); | 302 _onAssetController.add(_passThroughController.node); |
| 296 } else if (_passThroughController.node.state.isDirty) { | 303 } else if (_passThroughController.node.state.isDirty) { |
| 297 _passThroughController.setAvailable(input.asset); | 304 _passThroughController.setAvailable(input.asset); |
| 298 } | 305 } |
| 299 } | 306 } |
| 300 | 307 |
| 301 String toString() => "phase input in $_location for $input"; | 308 String toString() => "phase input in $_location for $input"; |
| 302 } | 309 } |
| OLD | NEW |