| 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.transform_node; | 5 library barback.transform_node; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'asset.dart'; | 9 import 'asset.dart'; |
| 10 import 'asset_id.dart'; | 10 import 'asset_id.dart'; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 /// began running. | 38 /// began running. |
| 39 bool get isDirty => _isDirty; | 39 bool get isDirty => _isDirty; |
| 40 var _isDirty = true; | 40 var _isDirty = true; |
| 41 | 41 |
| 42 /// The subscriptions to each input's [AssetNode.onStateChange] stream. | 42 /// The subscriptions to each input's [AssetNode.onStateChange] stream. |
| 43 var _inputSubscriptions = new Map<AssetId, StreamSubscription>(); | 43 var _inputSubscriptions = new Map<AssetId, StreamSubscription>(); |
| 44 | 44 |
| 45 /// The controllers for the asset nodes emitted by this node. | 45 /// The controllers for the asset nodes emitted by this node. |
| 46 var _outputControllers = new Map<AssetId, AssetNodeController>(); | 46 var _outputControllers = new Map<AssetId, AssetNodeController>(); |
| 47 | 47 |
| 48 /// A stream that emits an event whenever this transform becomes dirty and |
| 49 /// needs to be re-run. |
| 50 /// |
| 51 /// This may emit events when the transform was already dirty or while |
| 52 /// processing transforms. Events are emitted synchronously to ensure that the |
| 53 /// dirty state is thoroughly propagated as soon as any assets are changed. |
| 54 Stream get onDirty => _onDirtyController.stream; |
| 55 final _onDirtyController = new StreamController.broadcast(sync: true); |
| 56 |
| 48 TransformNode(this.phase, this.transformer, this.primary) { | 57 TransformNode(this.phase, this.transformer, this.primary) { |
| 49 _primarySubscription = primary.onStateChange.listen((state) { | 58 _primarySubscription = primary.onStateChange.listen((state) { |
| 50 if (state.isRemoved) { | 59 if (state.isRemoved) { |
| 51 remove(); | 60 remove(); |
| 52 } else { | 61 } else { |
| 53 _dirty(); | 62 _dirty(); |
| 54 } | 63 } |
| 55 }); | 64 }); |
| 56 } | 65 } |
| 57 | 66 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 73 } | 82 } |
| 74 | 83 |
| 75 /// Marks this transform as dirty. | 84 /// Marks this transform as dirty. |
| 76 /// | 85 /// |
| 77 /// This causes all of the transform's outputs to be marked as dirty as well. | 86 /// This causes all of the transform's outputs to be marked as dirty as well. |
| 78 void _dirty() { | 87 void _dirty() { |
| 79 _isDirty = true; | 88 _isDirty = true; |
| 80 for (var controller in _outputControllers.values) { | 89 for (var controller in _outputControllers.values) { |
| 81 controller.setDirty(); | 90 controller.setDirty(); |
| 82 } | 91 } |
| 92 _onDirtyController.add(null); |
| 83 } | 93 } |
| 84 | 94 |
| 85 /// Applies this transform. | 95 /// Applies this transform. |
| 86 /// | 96 /// |
| 87 /// Returns a set of asset nodes representing the outputs from this transform | 97 /// Returns a set of asset nodes representing the outputs from this transform |
| 88 /// that weren't emitted last time it was run. | 98 /// that weren't emitted last time it was run. |
| 89 Future<Set<AssetNode>> apply() { | 99 Future<Set<AssetNode>> apply() { |
| 90 var newOutputs = new AssetSet(); | 100 var newOutputs = new AssetSet(); |
| 91 var transform = createTransform(this, newOutputs); | 101 var transform = createTransform(this, newOutputs); |
| 92 | 102 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } else { | 183 } else { |
| 174 var controller = new AssetNodeController.available(asset); | 184 var controller = new AssetNodeController.available(asset); |
| 175 _outputControllers[asset.id] = controller; | 185 _outputControllers[asset.id] = controller; |
| 176 brandNewOutputs.add(controller.node); | 186 brandNewOutputs.add(controller.node); |
| 177 } | 187 } |
| 178 } | 188 } |
| 179 | 189 |
| 180 return brandNewOutputs; | 190 return brandNewOutputs; |
| 181 } | 191 } |
| 182 } | 192 } |
| OLD | NEW |