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

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

Issue 291843011: Run pub tests against older versions of barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 6 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 'phase.dart';
13 import 'stream_pool.dart';
14 import 'transform_node.dart';
15 import 'transformer.dart';
16
17 /// A class for watching a single [AssetNode] and running any transforms that
18 /// take that node as a primary input.
19 class PhaseInput {
20 /// The phase for which this is an input.
21 final Phase _phase;
22
23 /// A string describing the location of [this] in the transformer graph.
24 final String _location;
25
26 /// The transforms currently applicable to [input].
27 ///
28 /// These are the transforms that have been "wired up": they represent a
29 /// repeatable transformation of a single concrete set of inputs. "dart2js" is
30 /// a transformer. "dart2js on web/main.dart" is a transform.
31 final _transforms = new Set<TransformNode>();
32
33 /// A forwarder for the input [AssetNode] for this phase.
34 ///
35 /// This is used to mark the node as removed should the input ever be removed.
36 final AssetForwarder _inputForwarder;
37
38 /// The asset node for this input.
39 AssetNode get input => _inputForwarder.node;
40
41 /// A stream that emits an event whenever [this] is no longer dirty.
42 ///
43 /// This is synchronous in order to guarantee that it will emit an event as
44 /// soon as [isDirty] flips from `true` to `false`.
45 Stream get onDone => _onDoneController.stream;
46 final _onDoneController = new StreamController.broadcast(sync: true);
47
48 /// A stream that emits any new assets emitted by [this].
49 ///
50 /// Assets are emitted synchronously to ensure that any changes are thoroughly
51 /// propagated as soon as they occur.
52 Stream<AssetNode> get onAsset => _onAssetPool.stream;
53 final _onAssetPool = new StreamPool<AssetNode>.broadcast();
54
55 /// Whether [this] is dirty and still has more processing to do.
56 bool get isDirty => _transforms.any((transform) => transform.isDirty);
57
58 /// A stream that emits an event whenever any transforms that use [input] as
59 /// their primary input log an entry.
60 Stream<LogEntry> get onLog => _onLogPool.stream;
61 final _onLogPool = new StreamPool<LogEntry>.broadcast();
62
63 PhaseInput(this._phase, AssetNode input, this._location)
64 : _inputForwarder = new AssetForwarder(input) {
65 input.whenRemoved(remove);
66 }
67
68 /// Removes this input.
69 ///
70 /// This marks all outputs of the input as removed.
71 void remove() {
72 _onDoneController.close();
73 _onAssetPool.close();
74 _onLogPool.close();
75 _inputForwarder.close();
76 }
77
78 /// Set this input's transformers to [transformers].
79 void updateTransformers(Iterable<Transformer> newTransformersIterable) {
80 var newTransformers = newTransformersIterable.toSet();
81 for (var transform in _transforms.toList()) {
82 if (newTransformers.remove(transform.transformer)) continue;
83 transform.remove();
84 }
85
86 // The remaining [newTransformers] are those for which there are no
87 // transforms in [_transforms].
88 for (var transformer in newTransformers) {
89 var transform = new TransformNode(
90 _phase, transformer, input, _location);
91 _transforms.add(transform);
92
93 transform.onDone.listen((_) {
94 if (!isDirty) _onDoneController.add(null);
95 }, onDone: () => _transforms.remove(transform));
96
97 _onAssetPool.add(transform.onAsset);
98 _onLogPool.add(transform.onLog);
99 }
100 }
101
102 /// Force all [LazyTransformer]s' transforms in this input to begin producing
103 /// concrete assets.
104 void forceAllTransforms() {
105 for (var transform in _transforms) {
106 transform.force();
107 }
108 }
109
110 String toString() => "phase input in $_location for $input";
111 }
OLDNEW
« no previous file with comments | « third_party/pkg/barback-0.13.0/lib/src/phase_forwarder.dart ('k') | third_party/pkg/barback-0.13.0/lib/src/phase_output.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698