Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: pkg/barback/lib/src/phase_input.dart

Issue 249183005: Move common streams in barback to their own class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/barback/lib/src/phase.dart ('k') | pkg/barback/lib/src/transform_node.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8
9 import 'asset_forwarder.dart'; 9 import 'asset_forwarder.dart';
10 import 'asset_node.dart'; 10 import 'asset_node.dart';
11 import 'log.dart'; 11 import 'log.dart';
12 import 'node_streams.dart';
12 import 'phase.dart'; 13 import 'phase.dart';
13 import 'stream_pool.dart';
14 import 'transform_node.dart'; 14 import 'transform_node.dart';
15 import 'transformer.dart'; 15 import 'transformer.dart';
16 16
17 /// A class for watching a single [AssetNode] and running any transforms that 17 /// A class for watching a single [AssetNode] and running any transforms that
18 /// take that node as a primary input. 18 /// take that node as a primary input.
19 class PhaseInput { 19 class PhaseInput {
20 /// The phase for which this is an input. 20 /// The phase for which this is an input.
21 final Phase _phase; 21 final Phase _phase;
22 22
23 /// A string describing the location of [this] in the transformer graph. 23 /// A string describing the location of [this] in the transformer graph.
(...skipping 10 matching lines...) Expand all
34 /// 34 ///
35 /// This is used to mark the node as removed should the input ever be removed. 35 /// This is used to mark the node as removed should the input ever be removed.
36 final AssetForwarder _inputForwarder; 36 final AssetForwarder _inputForwarder;
37 37
38 /// The asset node for this input. 38 /// The asset node for this input.
39 AssetNode get input => _inputForwarder.node; 39 AssetNode get input => _inputForwarder.node;
40 40
41 /// The subscription to [input]'s [AssetNode.onStateChange] stream. 41 /// The subscription to [input]'s [AssetNode.onStateChange] stream.
42 StreamSubscription _inputSubscription; 42 StreamSubscription _inputSubscription;
43 43
44 /// A stream that emits an event whenever [this] is no longer dirty. 44 /// The streams exposed by this input.
45 /// 45 final _streams = new NodeStreams();
46 /// This is synchronous in order to guarantee that it will emit an event as 46 Stream get onDone => _streams.onDone;
47 /// soon as [isDirty] flips from `true` to `false`. 47 Stream<AssetNode> get onAsset => _streams.onAsset;
48 Stream get onDone => _onDoneController.stream; 48 Stream<LogEntry> get onLog => _streams.onLog;
49 final _onDoneController = new StreamController.broadcast(sync: true);
50
51 /// A stream that emits any new assets emitted by [this].
52 ///
53 /// Assets are emitted synchronously to ensure that any changes are thoroughly
54 /// propagated as soon as they occur.
55 Stream<AssetNode> get onAsset => _onAssetPool.stream;
56 final _onAssetPool = new StreamPool<AssetNode>.broadcast();
57 49
58 /// Whether [this] is dirty and still has more processing to do. 50 /// Whether [this] is dirty and still has more processing to do.
59 bool get isDirty => (input.state.isDirty && !input.deferred) || 51 bool get isDirty => (input.state.isDirty && !input.deferred) ||
60 _transforms.any((transform) => transform.isDirty); 52 _transforms.any((transform) => transform.isDirty);
61 53
62 /// A stream that emits an event whenever any transforms that use [input] as
63 /// their primary input log an entry.
64 Stream<LogEntry> get onLog => _onLogPool.stream;
65 final _onLogPool = new StreamPool<LogEntry>.broadcast();
66
67 PhaseInput(this._phase, AssetNode input, this._location) 54 PhaseInput(this._phase, AssetNode input, this._location)
68 : _inputForwarder = new AssetForwarder(input) { 55 : _inputForwarder = new AssetForwarder(input) {
69 _inputSubscription = input.onStateChange.listen((state) { 56 _inputSubscription = input.onStateChange.listen((state) {
70 if (state.isRemoved) { 57 if (state.isRemoved) {
71 remove(); 58 remove();
72 } else if (state.isAvailable) { 59 } else if (state.isAvailable) {
73 if (!isDirty) _onDoneController.add(null); 60 if (!isDirty) _streams.onDoneController.add(null);
74 } 61 }
75 }); 62 });
76 } 63 }
77 64
78 /// Removes this input. 65 /// Removes this input.
79 /// 66 ///
80 /// This marks all outputs of the input as removed. 67 /// This marks all outputs of the input as removed.
81 void remove() { 68 void remove() {
69 _streams.close();
82 _inputSubscription.cancel(); 70 _inputSubscription.cancel();
83 _onDoneController.close();
84 _onAssetPool.close();
85 _onLogPool.close();
86 _inputForwarder.close(); 71 _inputForwarder.close();
87 } 72 }
88 73
89 /// Set this input's transformers to [transformers]. 74 /// Set this input's transformers to [transformers].
90 void updateTransformers(Iterable<Transformer> newTransformersIterable) { 75 void updateTransformers(Iterable<Transformer> newTransformersIterable) {
91 var newTransformers = newTransformersIterable.toSet(); 76 var newTransformers = newTransformersIterable.toSet();
92 for (var transform in _transforms.toList()) { 77 for (var transform in _transforms.toList()) {
93 if (newTransformers.remove(transform.transformer)) continue; 78 if (newTransformers.remove(transform.transformer)) continue;
94 transform.remove(); 79 transform.remove();
95 } 80 }
96 81
97 // The remaining [newTransformers] are those for which there are no 82 // The remaining [newTransformers] are those for which there are no
98 // transforms in [_transforms]. 83 // transforms in [_transforms].
99 for (var transformer in newTransformers) { 84 for (var transformer in newTransformers) {
100 var transform = new TransformNode( 85 var transform = new TransformNode(
101 _phase, transformer, input, _location); 86 _phase, transformer, input, _location);
102 _transforms.add(transform); 87 _transforms.add(transform);
103 88
104 transform.onDone.listen((_) { 89 transform.onDone.listen((_) {
105 if (!isDirty) _onDoneController.add(null); 90 if (!isDirty) _streams.onDoneController.add(null);
106 }, onDone: () => _transforms.remove(transform)); 91 }, onDone: () => _transforms.remove(transform));
107 92
108 _onAssetPool.add(transform.onAsset); 93 _streams.onAssetPool.add(transform.onAsset);
109 _onLogPool.add(transform.onLog); 94 _streams.onLogPool.add(transform.onLog);
110 } 95 }
111 } 96 }
112 97
113 /// Force all [LazyTransformer]s' transforms in this input to begin producing 98 /// Force all [LazyTransformer]s' transforms in this input to begin producing
114 /// concrete assets. 99 /// concrete assets.
115 void forceAllTransforms() { 100 void forceAllTransforms() {
116 for (var transform in _transforms) { 101 for (var transform in _transforms) {
117 transform.force(); 102 transform.force();
118 } 103 }
119 } 104 }
120 105
121 String toString() => "phase input in $_location for $input"; 106 String toString() => "phase input in $_location for $input";
122 } 107 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/phase.dart ('k') | pkg/barback/lib/src/transform_node.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698