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

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

Issue 149243009: Add support for lazy transformers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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
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; 5 library barback.phase;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'asset_cascade.dart'; 9 import 'asset_cascade.dart';
10 import 'asset_id.dart'; 10 import 'asset_id.dart';
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 /// will automatically begin determining which transforms can consume it as a 129 /// will automatically begin determining which transforms can consume it as a
130 /// primary input. The transforms themselves won't be applied until [process] 130 /// primary input. The transforms themselves won't be applied until [process]
131 /// is called, however. 131 /// is called, however.
132 /// 132 ///
133 /// This should only be used for brand-new assets or assets that have been 133 /// This should only be used for brand-new assets or assets that have been
134 /// removed and re-created. The phase will automatically handle updated assets 134 /// removed and re-created. The phase will automatically handle updated assets
135 /// using the [AssetNode.onStateChange] stream. 135 /// using the [AssetNode.onStateChange] stream.
136 void addInput(AssetNode node) { 136 void addInput(AssetNode node) {
137 if (_inputs.containsKey(node.id)) _inputs[node.id].remove(); 137 if (_inputs.containsKey(node.id)) _inputs[node.id].remove();
138 138
139 node.materialize();
Bob Nystrom 2014/01/30 19:33:44 Why is this being materialized?
nweiz 2014/01/31 03:43:27 The phase needs its inputs to be available if it's
140
139 // Each group is one channel along which an asset may be forwarded. Then 141 // Each group is one channel along which an asset may be forwarded. Then
140 // there's one additional channel for the non-grouped transformers. 142 // there's one additional channel for the non-grouped transformers.
141 var forwarder = new PhaseForwarder(_groups.length + 1); 143 var forwarder = new PhaseForwarder(_groups.length + 1);
142 _forwarders[node.id] = forwarder; 144 _forwarders[node.id] = forwarder;
143 forwarder.onForwarding.listen((asset) { 145 forwarder.onForwarding.listen((asset) {
144 _addOutput(asset); 146 _addOutput(asset);
145 147
146 var exception = _outputs[asset.id].collisionException; 148 var exception = _outputs[asset.id].collisionException;
147 if (exception != null) cascade.reportError(exception); 149 if (exception != null) cascade.reportError(exception);
148 }); 150 });
(...skipping 26 matching lines...) Expand all
175 }); 177 });
176 } 178 }
177 179
178 /// Gets the asset node for an output [id]. 180 /// Gets the asset node for an output [id].
179 /// 181 ///
180 /// If an output with that ID cannot be found, returns null. 182 /// If an output with that ID cannot be found, returns null.
181 Future<AssetNode> getOutput(AssetId id) { 183 Future<AssetNode> getOutput(AssetId id) {
182 return newFuture(() { 184 return newFuture(() {
183 if (id.package != cascade.package) return cascade.graph.getAssetNode(id); 185 if (id.package != cascade.package) return cascade.graph.getAssetNode(id);
184 if (!_outputs.containsKey(id)) return null; 186 if (!_outputs.containsKey(id)) return null;
185 return _outputs[id].output; 187 return _outputs[id].output..materialize();
Bob Nystrom 2014/01/30 19:33:44 Nit, but I'm really not a fan of using a single ca
nweiz 2014/01/31 03:43:27 I think it's nicer than making a variable, but oka
186 }); 188 });
187 } 189 }
188 190
189 /// Set this phase's transformers to [transformers]. 191 /// Set this phase's transformers to [transformers].
190 void updateTransformers(Iterable transformers) { 192 void updateTransformers(Iterable transformers) {
191 _onDirtyController.add(null); 193 _onDirtyController.add(null);
192 194
193 var actualTransformers = transformers.where((op) => op is Transformer); 195 var actualTransformers = transformers.where((op) => op is Transformer);
194 _transformers.clear(); 196 _transformers.clear();
195 _transformers.addAll(actualTransformers); 197 _transformers.addAll(actualTransformers);
(...skipping 16 matching lines...) Expand all
212 for (var input in _inputs.values) { 214 for (var input in _inputs.values) {
213 runner.addInput(input.input); 215 runner.addInput(input.input);
214 } 216 }
215 } 217 }
216 218
217 for (var forwarder in _forwarders.values) { 219 for (var forwarder in _forwarders.values) {
218 forwarder.numChannels = _groups.length + 1; 220 forwarder.numChannels = _groups.length + 1;
219 } 221 }
220 } 222 }
221 223
224 /// Materialize all [LazyTransformer]s' transforms in this group.
225 void materializeAllTransforms() {
226 for (var group in _groups.values) {
227 group.materializeAllTransforms();
228 }
229
230 for (var input in _inputs.values) {
231 input.materializeAllTransforms();
232 }
233 }
234
222 /// Add a new phase after this one with [transformers]. 235 /// Add a new phase after this one with [transformers].
223 /// 236 ///
224 /// This may only be called on a phase with no phase following it. 237 /// This may only be called on a phase with no phase following it.
225 Phase addPhase(Iterable transformers) { 238 Phase addPhase(Iterable transformers) {
226 assert(_next == null); 239 assert(_next == null);
227 _next = new Phase(cascade, transformers); 240 _next = new Phase(cascade, transformers);
228 for (var output in _outputs.values.toList()) { 241 for (var output in _outputs.values.toList()) {
229 // Remove [output]'s listeners because now they should get the asset from 242 // Remove [output]'s listeners because now they should get the asset from
230 // [_next], rather than this phase. Any transforms consuming [output] will 243 // [_next], rather than this phase. Any transforms consuming [output] will
231 // be re-run and will consume the output from the new final phase. 244 // be re-run and will consume the output from the new final phase.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 _outputs[asset.id].add(asset); 319 _outputs[asset.id].add(asset);
307 } else { 320 } else {
308 _outputs[asset.id] = new PhaseOutput(this, asset); 321 _outputs[asset.id] = new PhaseOutput(this, asset);
309 _outputs[asset.id].onAsset.listen((output) { 322 _outputs[asset.id].onAsset.listen((output) {
310 if (_next != null) _next.addInput(output); 323 if (_next != null) _next.addInput(output);
311 }, onDone: () => _outputs.remove(asset.id)); 324 }, onDone: () => _outputs.remove(asset.id));
312 if (_next != null) _next.addInput(_outputs[asset.id].output); 325 if (_next != null) _next.addInput(_outputs[asset.id].output);
313 } 326 }
314 } 327 }
315 } 328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698