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

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

Issue 260833006: Remove PhaseInput and add TransformerSorter to barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename "sorter" to "classifier". 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library barback.phase_input;
6
7 import 'dart:async';
8
9 import 'asset_forwarder.dart';
10 import 'asset_node.dart';
11 import 'log.dart';
12 import 'node_status.dart';
13 import 'node_streams.dart';
14 import 'phase.dart';
15 import 'transform_node.dart';
16 import 'transformer.dart';
17
18 /// A class for watching a single [AssetNode] and running any transforms that
19 /// take that node as a primary input.
20 class PhaseInput {
21 /// The phase for which this is an input.
22 final Phase _phase;
23
24 /// A string describing the location of [this] in the transformer graph.
25 final String _location;
26
27 /// The transforms currently applicable to [input].
28 ///
29 /// These are the transforms that have been "wired up": they represent a
30 /// repeatable transformation of a single concrete set of inputs. "dart2js" is
31 /// a transformer. "dart2js on web/main.dart" is a transform.
32 final _transforms = new Set<TransformNode>();
33
34 /// A forwarder for the input [AssetNode] for this phase.
35 ///
36 /// This is used to mark the node as removed should the input ever be removed.
37 final AssetForwarder _inputForwarder;
38
39 /// The asset node for this input.
40 AssetNode get input => _inputForwarder.node;
41
42 /// The subscription to [input]'s [AssetNode.onStateChange] stream.
43 StreamSubscription _inputSubscription;
44
45 /// The streams exposed by this input.
46 final _streams = new NodeStreams();
47 Stream get onStatusChange => _streams.onStatusChange;
48 Stream<AssetNode> get onAsset => _streams.onAsset;
49 Stream<LogEntry> get onLog => _streams.onLog;
50
51 /// How far along [this] is in processing its assets.
52 NodeStatus get status {
53 var status = input.state.isDirty && !input.isLazy ?
54 NodeStatus.MATERIALIZING : NodeStatus.IDLE;
55 return status.dirtier(NodeStatus.dirtiest(
56 _transforms.map((transform) => transform.status)));
57 }
58
59 PhaseInput(this._phase, AssetNode input, this._location)
60 : _inputForwarder = new AssetForwarder(input) {
61 _inputSubscription = input.onStateChange.listen((state) {
62 if (state.isRemoved) {
63 remove();
64 } else {
65 _streams.changeStatus(status);
66 }
67 });
68 }
69
70 /// Removes this input.
71 ///
72 /// This marks all outputs of the input as removed.
73 void remove() {
74 _streams.close();
75 _inputSubscription.cancel();
76 _inputForwarder.close();
77 }
78
79 /// Set this input's transformers to [transformers].
80 void updateTransformers(Iterable<Transformer> newTransformersIterable) {
81 var newTransformers = newTransformersIterable.toSet();
82 for (var transform in _transforms.toList()) {
83 if (newTransformers.remove(transform.transformer)) continue;
84 transform.remove();
85 }
86
87 // The remaining [newTransformers] are those for which there are no
88 // transforms in [_transforms].
89 for (var transformer in newTransformers) {
90 var transform = new TransformNode(
91 _phase, transformer, input, _location);
92 _transforms.add(transform);
93
94 transform.onStatusChange.listen(
95 (_) => _streams.changeStatus(status),
96 onDone: () => _transforms.remove(transform));
97
98 _streams.onAssetPool.add(transform.onAsset);
99 _streams.onLogPool.add(transform.onLog);
100 }
101 }
102
103 /// Force all [LazyTransformer]s' transforms in this input to begin producing
104 /// concrete assets.
105 void forceAllTransforms() {
106 for (var transform in _transforms) {
107 transform.force();
108 }
109 }
110
111 String toString() => "phase input in $_location for $input";
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698