| 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 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'asset.dart'; | 10 import 'asset.dart'; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 _onDirtyController.add(null); | 101 _onDirtyController.add(null); |
| 102 _onDirtyPool.close(); | 102 _onDirtyPool.close(); |
| 103 _inputForwarder.close(); | 103 _inputForwarder.close(); |
| 104 if (_passThroughController != null) { | 104 if (_passThroughController != null) { |
| 105 _passThroughController.setRemoved(); | 105 _passThroughController.setRemoved(); |
| 106 _passThroughController = null; | 106 _passThroughController = null; |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 /// Set this input's transformers to [transformers]. | 110 /// Set this input's transformers to [transformers]. |
| 111 void updateTransformers(Set<Transformer> newTransformers) { | 111 void updateTransformers(Iterable<Transformer> newTransformers) { |
| 112 newTransformers = newTransformers.toSet(); |
| 112 var oldTransformers = _transformers.toSet(); | 113 var oldTransformers = _transformers.toSet(); |
| 113 for (var removedTransformer in | 114 for (var removedTransformer in |
| 114 oldTransformers.difference(newTransformers)) { | 115 oldTransformers.difference(newTransformers)) { |
| 115 _transformers.remove(removedTransformer); | 116 _transformers.remove(removedTransformer); |
| 116 | 117 |
| 117 // If the transformers are being adjusted for [id], it will | 118 // If the transformers are being adjusted for [id], it will |
| 118 // automatically pick up on [removedTransformer] being gone. | 119 // automatically pick up on [removedTransformer] being gone. |
| 119 if (_adjustTransformersFuture != null) continue; | 120 if (_adjustTransformersFuture != null) continue; |
| 120 | 121 |
| 121 _transforms.removeWhere((transform) { | 122 _transforms.removeWhere((transform) { |
| 122 if (transform.transformer != removedTransformer) return false; | 123 if (transform.transformer != removedTransformer) return false; |
| 123 transform.remove(); | 124 transform.remove(); |
| 124 return true; | 125 return true; |
| 125 }); | 126 }); |
| 126 } | 127 } |
| 127 | 128 |
| 128 if (_transforms.isEmpty && _adjustTransformersFuture == null && | 129 if (_transforms.isEmpty && _adjustTransformersFuture == null && |
| 129 _passThroughController == null) { | 130 _passThroughController == null) { |
| 130 _passThroughController = | 131 _passThroughController = new AssetNodeController.from(input); |
| 131 new AssetNodeController.available(input.asset, input.transform); | |
| 132 _newPassThrough = true; | 132 _newPassThrough = true; |
| 133 } | 133 } |
| 134 | 134 |
| 135 var brandNewTransformers = newTransformers.difference(oldTransformers); | 135 var brandNewTransformers = newTransformers.difference(oldTransformers); |
| 136 if (brandNewTransformers.isEmpty) return; | 136 if (brandNewTransformers.isEmpty) return; |
| 137 | 137 |
| 138 brandNewTransformers.forEach(_transformers.add); | 138 brandNewTransformers.forEach(_transformers.add); |
| 139 if (_adjustTransformersFuture == null) _adjustTransformers(); | 139 if (_adjustTransformersFuture == null) _adjustTransformers(); |
| 140 } | 140 } |
| 141 | 141 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 /// | 233 /// |
| 234 /// If [input] was already passed-through, this will update the passed-through | 234 /// If [input] was already passed-through, this will update the passed-through |
| 235 /// value. | 235 /// value. |
| 236 void _adjustPassThrough() { | 236 void _adjustPassThrough() { |
| 237 assert(input.state.isAvailable); | 237 assert(input.state.isAvailable); |
| 238 | 238 |
| 239 if (_transforms.isEmpty) { | 239 if (_transforms.isEmpty) { |
| 240 if (_passThroughController != null) { | 240 if (_passThroughController != null) { |
| 241 _passThroughController.setAvailable(input.asset); | 241 _passThroughController.setAvailable(input.asset); |
| 242 } else { | 242 } else { |
| 243 _passThroughController = | 243 _passThroughController = new AssetNodeController.from(input); |
| 244 new AssetNodeController.available(input.asset, input.transform); | |
| 245 _newPassThrough = true; | 244 _newPassThrough = true; |
| 246 } | 245 } |
| 247 } else if (_passThroughController != null) { | 246 } else if (_passThroughController != null) { |
| 248 _passThroughController.setRemoved(); | 247 _passThroughController.setRemoved(); |
| 249 _passThroughController = null; | 248 _passThroughController = null; |
| 250 _newPassThrough = false; | 249 _newPassThrough = false; |
| 251 } | 250 } |
| 252 } | 251 } |
| 253 | 252 |
| 254 /// Like [AssetNode.tryUntilStable], but also re-runs [callback] if this | 253 /// Like [AssetNode.tryUntilStable], but also re-runs [callback] if this |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 return new Future.value( | 287 return new Future.value( |
| 289 new Set<AssetNode>.from([_passThroughController.node])); | 288 new Set<AssetNode>.from([_passThroughController.node])); |
| 290 } | 289 } |
| 291 | 290 |
| 292 return Future.wait(_transforms.map((transform) { | 291 return Future.wait(_transforms.map((transform) { |
| 293 if (!transform.isDirty) return new Future.value(new Set()); | 292 if (!transform.isDirty) return new Future.value(new Set()); |
| 294 return transform.apply(); | 293 return transform.apply(); |
| 295 })).then((outputs) => unionAll(outputs)); | 294 })).then((outputs) => unionAll(outputs)); |
| 296 } | 295 } |
| 297 } | 296 } |
| OLD | NEW |