Chromium Code Reviews| 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.dart'; | 9 import 'asset.dart'; |
| 10 import 'asset_cascade.dart'; | 10 import 'asset_cascade.dart'; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 | 134 |
| 135 _newInputs.clear(); | 135 _newInputs.clear(); |
| 136 | 136 |
| 137 return Future.wait(futures); | 137 return Future.wait(futures); |
| 138 } | 138 } |
| 139 | 139 |
| 140 /// Applies all currently wired up and dirty transforms. | 140 /// Applies all currently wired up and dirty transforms. |
| 141 /// | 141 /// |
| 142 /// Passes their outputs to the next phase. | 142 /// Passes their outputs to the next phase. |
| 143 Future _processTransforms() { | 143 Future _processTransforms() { |
| 144 var dirtyTransforms = _transforms.where((transform) => transform.isDirty); | 144 // Convert this to a list so we can safely modify _transforms while |
| 145 // iterating over it. | |
| 146 var dirtyTransforms = _transforms.where((transform) => transform.isDirty) | |
| 147 .toList(); | |
| 145 if (dirtyTransforms.isEmpty) return null; | 148 if (dirtyTransforms.isEmpty) return null; |
| 146 | 149 |
| 147 return Future.wait(dirtyTransforms.map((transform) => transform.apply())) | 150 return Future.wait(dirtyTransforms.map((transform) { |
| 148 .then((transformOutputs) { | 151 if (inputs.containsKey(transform.primary.id)) return transform.apply(); |
| 152 | |
| 153 // If the primary input for the transform has been removed, get rid of it | |
| 154 // and all its outputs. | |
| 155 _transforms.remove(transform); | |
| 156 return new Future.value( | |
| 157 new TransformOutputs(new AssetSet(), transform.outputs)); | |
|
Bob Nystrom
2013/07/17 17:18:26
Smart way to handle this. :)
| |
| 158 })).then((transformOutputs) { | |
| 149 // Collect all of the outputs. Since the transforms are run in parallel, | 159 // Collect all of the outputs. Since the transforms are run in parallel, |
| 150 // we have to be careful here to ensure that the result is deterministic | 160 // we have to be careful here to ensure that the result is deterministic |
| 151 // and not influenced by the order that transforms complete. | 161 // and not influenced by the order that transforms complete. |
| 152 var updated = new AssetSet(); | 162 var updated = new AssetSet(); |
| 153 var removed = new Set<AssetId>(); | 163 var removed = new Set<AssetId>(); |
| 154 var collisions = new Set<AssetId>(); | 164 var collisions = new Set<AssetId>(); |
| 155 | 165 |
| 156 // Handle the generated outputs of all transforms first. | 166 // Handle the generated outputs of all transforms first. |
| 157 for (var outputs in transformOutputs) { | 167 for (var outputs in transformOutputs) { |
| 158 // Collect the outputs of all transformers together. | 168 // Collect the outputs of all transformers together. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 179 for (var collision in collisions) { | 189 for (var collision in collisions) { |
| 180 cascade.reportError(new AssetCollisionException(collision)); | 190 cascade.reportError(new AssetCollisionException(collision)); |
| 181 // TODO(rnystrom): Define what happens after a collision occurs. | 191 // TODO(rnystrom): Define what happens after a collision occurs. |
| 182 } | 192 } |
| 183 | 193 |
| 184 // Pass the outputs to the next phase. | 194 // Pass the outputs to the next phase. |
| 185 _next.updateInputs(updated, removed); | 195 _next.updateInputs(updated, removed); |
| 186 }); | 196 }); |
| 187 } | 197 } |
| 188 } | 198 } |
| OLD | NEW |