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

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

Issue 255483002: Expand barback's notion of dirtiness to understand declaredness. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 7 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_status.dart';
12 import 'node_streams.dart'; 13 import 'node_streams.dart';
13 import 'phase.dart'; 14 import 'phase.dart';
14 import 'transform_node.dart'; 15 import 'transform_node.dart';
15 import 'transformer.dart'; 16 import 'transformer.dart';
16 17
17 /// A class for watching a single [AssetNode] and running any transforms that 18 /// A class for watching a single [AssetNode] and running any transforms that
18 /// take that node as a primary input. 19 /// take that node as a primary input.
19 class PhaseInput { 20 class PhaseInput {
20 /// The phase for which this is an input. 21 /// The phase for which this is an input.
21 final Phase _phase; 22 final Phase _phase;
(...skipping 14 matching lines...) Expand all
36 final AssetForwarder _inputForwarder; 37 final AssetForwarder _inputForwarder;
37 38
38 /// The asset node for this input. 39 /// The asset node for this input.
39 AssetNode get input => _inputForwarder.node; 40 AssetNode get input => _inputForwarder.node;
40 41
41 /// The subscription to [input]'s [AssetNode.onStateChange] stream. 42 /// The subscription to [input]'s [AssetNode.onStateChange] stream.
42 StreamSubscription _inputSubscription; 43 StreamSubscription _inputSubscription;
43 44
44 /// The streams exposed by this input. 45 /// The streams exposed by this input.
45 final _streams = new NodeStreams(); 46 final _streams = new NodeStreams();
46 Stream get onDone => _streams.onDone; 47 Stream get onStatusChange => _streams.onStatusChange;
47 Stream<AssetNode> get onAsset => _streams.onAsset; 48 Stream<AssetNode> get onAsset => _streams.onAsset;
48 Stream<LogEntry> get onLog => _streams.onLog; 49 Stream<LogEntry> get onLog => _streams.onLog;
49 50
50 /// Whether [this] is dirty and still has more processing to do. 51 /// How far along [this] is in processing its assets.
51 bool get isDirty => (input.state.isDirty && !input.deferred) || 52 NodeStatus get status {
52 _transforms.any((transform) => transform.isDirty); 53 var status = input.state.isDirty && !input.deferred ?
54 NodeStatus.MATERIALIZING : NodeStatus.IDLE;
55 return status.dirtier(NodeStatus.dirtiest(
56 _transforms.map((transform) => transform.status)));
57 }
53 58
54 PhaseInput(this._phase, AssetNode input, this._location) 59 PhaseInput(this._phase, AssetNode input, this._location)
55 : _inputForwarder = new AssetForwarder(input) { 60 : _inputForwarder = new AssetForwarder(input) {
56 _inputSubscription = input.onStateChange.listen((state) { 61 _inputSubscription = input.onStateChange.listen((state) {
57 if (state.isRemoved) { 62 if (state.isRemoved) {
58 remove(); 63 remove();
59 } else if (state.isAvailable) { 64 } else {
60 if (!isDirty) _streams.onDoneController.add(null); 65 _streams.changeStatus(status);
61 } 66 }
62 }); 67 });
63 } 68 }
64 69
65 /// Removes this input. 70 /// Removes this input.
66 /// 71 ///
67 /// This marks all outputs of the input as removed. 72 /// This marks all outputs of the input as removed.
68 void remove() { 73 void remove() {
69 _streams.close(); 74 _streams.close();
70 _inputSubscription.cancel(); 75 _inputSubscription.cancel();
71 _inputForwarder.close(); 76 _inputForwarder.close();
72 } 77 }
73 78
74 /// Set this input's transformers to [transformers]. 79 /// Set this input's transformers to [transformers].
75 void updateTransformers(Iterable<Transformer> newTransformersIterable) { 80 void updateTransformers(Iterable<Transformer> newTransformersIterable) {
76 var newTransformers = newTransformersIterable.toSet(); 81 var newTransformers = newTransformersIterable.toSet();
77 for (var transform in _transforms.toList()) { 82 for (var transform in _transforms.toList()) {
78 if (newTransformers.remove(transform.transformer)) continue; 83 if (newTransformers.remove(transform.transformer)) continue;
79 transform.remove(); 84 transform.remove();
80 } 85 }
81 86
82 // The remaining [newTransformers] are those for which there are no 87 // The remaining [newTransformers] are those for which there are no
83 // transforms in [_transforms]. 88 // transforms in [_transforms].
84 for (var transformer in newTransformers) { 89 for (var transformer in newTransformers) {
85 var transform = new TransformNode( 90 var transform = new TransformNode(
86 _phase, transformer, input, _location); 91 _phase, transformer, input, _location);
87 _transforms.add(transform); 92 _transforms.add(transform);
88 93
89 transform.onDone.listen((_) { 94 transform.onStatusChange.listen(
90 if (!isDirty) _streams.onDoneController.add(null); 95 (_) => _streams.changeStatus(status),
91 }, onDone: () => _transforms.remove(transform)); 96 onDone: () => _transforms.remove(transform));
92 97
93 _streams.onAssetPool.add(transform.onAsset); 98 _streams.onAssetPool.add(transform.onAsset);
94 _streams.onLogPool.add(transform.onLog); 99 _streams.onLogPool.add(transform.onLog);
95 } 100 }
96 } 101 }
97 102
98 /// Force all [LazyTransformer]s' transforms in this input to begin producing 103 /// Force all [LazyTransformer]s' transforms in this input to begin producing
99 /// concrete assets. 104 /// concrete assets.
100 void forceAllTransforms() { 105 void forceAllTransforms() {
101 for (var transform in _transforms) { 106 for (var transform in _transforms) {
102 transform.force(); 107 transform.force();
103 } 108 }
104 } 109 }
105 110
106 String toString() => "phase input in $_location for $input"; 111 String toString() => "phase input in $_location for $input";
107 } 112 }
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