| 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.asset_cascade; | 5 library barback.asset_cascade; |
| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 /// A future that completes when the currently running build process finishes. | 92 /// A future that completes when the currently running build process finishes. |
| 93 /// | 93 /// |
| 94 /// If no build it in progress, is `null`. | 94 /// If no build it in progress, is `null`. |
| 95 Future _processDone; | 95 Future _processDone; |
| 96 | 96 |
| 97 /// Whether any source assets have been updated or removed since processing | 97 /// Whether any source assets have been updated or removed since processing |
| 98 /// last began. | 98 /// last began. |
| 99 var _newChanges = false; | 99 var _newChanges = false; |
| 100 | 100 |
| 101 /// Returns all currently-available output assets from this cascade. | 101 /// Returns all currently-available output assets from this cascade. |
| 102 AssetSet get availableOutputs => _phases.last.availableOutputs; | 102 AssetSet get availableOutputs => |
| 103 new AssetSet.from(_phases.last.availableOutputs.map((node) => node.asset)); |
| 103 | 104 |
| 104 /// Creates a new [AssetCascade]. | 105 /// Creates a new [AssetCascade]. |
| 105 /// | 106 /// |
| 106 /// It loads source assets within [package] using [provider]. | 107 /// It loads source assets within [package] using [provider]. |
| 107 AssetCascade(this.graph, this.package) { | 108 AssetCascade(this.graph, this.package) { |
| 108 _onDirtyPool.add(_onDirtyController.stream); | 109 _onDirtyPool.add(_onDirtyController.stream); |
| 109 _addPhase(new Phase(this, [])); | 110 _addPhase(new Phase(this, [])); |
| 110 } | 111 } |
| 111 | 112 |
| 112 /// Gets the asset identified by [id]. | 113 /// Gets the asset identified by [id]. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 removed.forEach((id) { | 183 removed.forEach((id) { |
| 183 // If the source was being loaded, cancel that load. | 184 // If the source was being loaded, cancel that load. |
| 184 if (_loadingSources.containsKey(id)) _loadingSources.remove(id).cancel(); | 185 if (_loadingSources.containsKey(id)) _loadingSources.remove(id).cancel(); |
| 185 | 186 |
| 186 var controller = _sourceControllerMap.remove(id); | 187 var controller = _sourceControllerMap.remove(id); |
| 187 // Don't choke if an id is double-removed for some reason. | 188 // Don't choke if an id is double-removed for some reason. |
| 188 if (controller != null) controller.setRemoved(); | 189 if (controller != null) controller.setRemoved(); |
| 189 }); | 190 }); |
| 190 } | 191 } |
| 191 | 192 |
| 192 /// Sets this cascade's transformer phases to [transformers]. | 193 /// Sets this cascade's operator phases to [operators]. |
| 193 void updateTransformers(Iterable<Iterable<Transformer>> transformers) { | 194 void updateOperators(Iterable<Iterable<Operator>> operators) { |
| 194 transformers = transformers.toList(); | 195 operators = operators.toList(); |
| 195 | 196 |
| 196 for (var i = 0; i < transformers.length; i++) { | 197 for (var i = 0; i < operators.length; i++) { |
| 197 if (_phases.length > i) { | 198 if (_phases.length > i) { |
| 198 _phases[i].updateTransformers(transformers[i]); | 199 _phases[i].updateOperators(operators[i]); |
| 199 continue; | 200 continue; |
| 200 } | 201 } |
| 201 | 202 |
| 202 _addPhase(_phases.last.addPhase(transformers[i])); | 203 _addPhase(_phases.last.addPhase(operators[i])); |
| 203 } | 204 } |
| 204 | 205 |
| 205 if (transformers.length == 0) { | 206 if (operators.length == 0) { |
| 206 _phases.last.updateTransformers([]); | 207 _phases.last.updateOperators([]); |
| 207 } else if (transformers.length < _phases.length) { | 208 } else if (operators.length < _phases.length) { |
| 208 _phases[transformers.length - 1].removeFollowing(); | 209 _phases[operators.length - 1].removeFollowing(); |
| 209 _phases.removeRange(transformers.length, _phases.length); | 210 _phases.removeRange(operators.length, _phases.length); |
| 210 } | 211 } |
| 211 } | 212 } |
| 212 | 213 |
| 213 void reportError(BarbackException error) { | 214 void reportError(BarbackException error) { |
| 214 _accumulatedErrors.add(error); | 215 _accumulatedErrors.add(error); |
| 215 _errorsController.add(error); | 216 _errorsController.add(error); |
| 216 } | 217 } |
| 217 | 218 |
| 218 /// Add [phase] to the end of [_phases] and watch its [onDirty] stream. | 219 /// Add [phase] to the end of [_phases] and watch its [onDirty] stream. |
| 219 void _addPhase(Phase phase) { | 220 void _addPhase(Phase phase) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 277 |
| 277 // Otherwise, everything is done. | 278 // Otherwise, everything is done. |
| 278 return; | 279 return; |
| 279 } | 280 } |
| 280 | 281 |
| 281 // Process that phase and then loop onto the next. | 282 // Process that phase and then loop onto the next. |
| 282 return future.then((_) => _process()); | 283 return future.then((_) => _process()); |
| 283 }); | 284 }); |
| 284 } | 285 } |
| 285 } | 286 } |
| OLD | NEW |