| 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 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'asset_cascade.dart'; | 10 import 'asset_cascade.dart'; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 _next = new Phase(cascade, transformers); | 141 _next = new Phase(cascade, transformers); |
| 142 for (var output in _outputs.values.toList()) { | 142 for (var output in _outputs.values.toList()) { |
| 143 // Remove [output]'s listeners because now they should get the asset from | 143 // Remove [output]'s listeners because now they should get the asset from |
| 144 // [_next], rather than this phase. Any transforms consuming [output] will | 144 // [_next], rather than this phase. Any transforms consuming [output] will |
| 145 // be re-run and will consume the output from the new final phase. | 145 // be re-run and will consume the output from the new final phase. |
| 146 output.removeListeners(); | 146 output.removeListeners(); |
| 147 | 147 |
| 148 // Removing [output]'s listeners will cause it to be removed from | 148 // Removing [output]'s listeners will cause it to be removed from |
| 149 // [_outputs], so we have to put it back. | 149 // [_outputs], so we have to put it back. |
| 150 _outputs[output.output.id] = output; | 150 _outputs[output.output.id] = output; |
| 151 output.output.whenRemoved.then((_) => _outputs.remove(output.output.id)); |
| 151 _next.addInput(output.output); | 152 _next.addInput(output.output); |
| 152 } | 153 } |
| 153 return _next; | 154 return _next; |
| 154 } | 155 } |
| 155 | 156 |
| 156 /// Mark this phase as removed. | 157 /// Mark this phase as removed. |
| 157 /// | 158 /// |
| 158 /// This will remove all the phase's outputs and all following phases. | 159 /// This will remove all the phase's outputs and all following phases. |
| 159 void remove() { | 160 void remove() { |
| 160 removeFollowing(); | 161 removeFollowing(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 181 var outputIds = new Set<AssetId>(); | 182 var outputIds = new Set<AssetId>(); |
| 182 return Future.wait(_inputs.values.map((input) { | 183 return Future.wait(_inputs.values.map((input) { |
| 183 if (!input.isDirty) return new Future.value(new Set()); | 184 if (!input.isDirty) return new Future.value(new Set()); |
| 184 return input.process().then((outputs) { | 185 return input.process().then((outputs) { |
| 185 for (var asset in outputs) { | 186 for (var asset in outputs) { |
| 186 outputIds.add(asset.id); | 187 outputIds.add(asset.id); |
| 187 if (_outputs.containsKey(asset.id)) { | 188 if (_outputs.containsKey(asset.id)) { |
| 188 _outputs[asset.id].add(asset); | 189 _outputs[asset.id].add(asset); |
| 189 } else { | 190 } else { |
| 190 _outputs[asset.id] = new PhaseOutput(this, asset); | 191 _outputs[asset.id] = new PhaseOutput(this, asset); |
| 191 _outputs[asset.id].output.whenRemoved | 192 _outputs[asset.id].output.whenRemoved.then((_) { |
| 192 .then((_) => _outputs.remove(asset.id)); | 193 _outputs.remove(asset.id); |
| 194 }); |
| 193 if (_next != null) _next.addInput(_outputs[asset.id].output); | 195 if (_next != null) _next.addInput(_outputs[asset.id].output); |
| 194 } | 196 } |
| 195 } | 197 } |
| 196 }); | 198 }); |
| 197 })).then((_) { | 199 })).then((_) { |
| 198 // Report collisions in a deterministic order. | 200 // Report collisions in a deterministic order. |
| 199 outputIds = outputIds.toList(); | 201 outputIds = outputIds.toList(); |
| 200 outputIds.sort((a, b) => a.compareTo(b)); | 202 outputIds.sort((a, b) => a.compareTo(b)); |
| 201 for (var id in outputIds) { | 203 for (var id in outputIds) { |
| 202 // It's possible the output was removed before other transforms in this | 204 // It's possible the output was removed before other transforms in this |
| 203 // phase finished. | 205 // phase finished. |
| 204 if (!_outputs.containsKey(id)) continue; | 206 if (!_outputs.containsKey(id)) continue; |
| 205 var exception = _outputs[id].collisionException; | 207 var exception = _outputs[id].collisionException; |
| 206 if (exception != null) cascade.reportError(exception); | 208 if (exception != null) cascade.reportError(exception); |
| 207 } | 209 } |
| 208 }); | 210 }); |
| 209 } | 211 } |
| 210 } | 212 } |
| OLD | NEW |