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

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: code review 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
« no previous file with comments | « pkg/barback/lib/src/package_graph.dart ('k') | pkg/barback/lib/src/phase_input.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; 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 /// will automatically begin determining which transforms can consume it as a 138 /// will automatically begin determining which transforms can consume it as a
139 /// primary input. The transforms themselves won't be applied until [process] 139 /// primary input. The transforms themselves won't be applied until [process]
140 /// is called, however. 140 /// is called, however.
141 /// 141 ///
142 /// This should only be used for brand-new assets or assets that have been 142 /// This should only be used for brand-new assets or assets that have been
143 /// removed and re-created. The phase will automatically handle updated assets 143 /// removed and re-created. The phase will automatically handle updated assets
144 /// using the [AssetNode.onStateChange] stream. 144 /// using the [AssetNode.onStateChange] stream.
145 void addInput(AssetNode node) { 145 void addInput(AssetNode node) {
146 if (_inputs.containsKey(node.id)) _inputs[node.id].remove(); 146 if (_inputs.containsKey(node.id)) _inputs[node.id].remove();
147 147
148 node.force();
149
148 // Each group is one channel along which an asset may be forwarded. Then 150 // Each group is one channel along which an asset may be forwarded. Then
149 // there's one additional channel for the non-grouped transformers. 151 // there's one additional channel for the non-grouped transformers.
150 var forwarder = new PhaseForwarder(_groups.length + 1); 152 var forwarder = new PhaseForwarder(_groups.length + 1);
151 _forwarders[node.id] = forwarder; 153 _forwarders[node.id] = forwarder;
152 forwarder.onForwarding.listen((asset) { 154 forwarder.onForwarding.listen((asset) {
153 _addOutput(asset); 155 _addOutput(asset);
154 156
155 var exception = _outputs[asset.id].collisionException; 157 var exception = _outputs[asset.id].collisionException;
156 if (exception != null) cascade.reportError(exception); 158 if (exception != null) cascade.reportError(exception);
157 }); 159 });
(...skipping 26 matching lines...) Expand all
184 }); 186 });
185 } 187 }
186 188
187 /// Gets the asset node for an output [id]. 189 /// Gets the asset node for an output [id].
188 /// 190 ///
189 /// If an output with that ID cannot be found, returns null. 191 /// If an output with that ID cannot be found, returns null.
190 Future<AssetNode> getOutput(AssetId id) { 192 Future<AssetNode> getOutput(AssetId id) {
191 return newFuture(() { 193 return newFuture(() {
192 if (id.package != cascade.package) return cascade.graph.getAssetNode(id); 194 if (id.package != cascade.package) return cascade.graph.getAssetNode(id);
193 if (!_outputs.containsKey(id)) return null; 195 if (!_outputs.containsKey(id)) return null;
194 return _outputs[id].output; 196 var output = _outputs[id].output;
197 output.force();
198 return output;
195 }); 199 });
196 } 200 }
197 201
198 /// Set this phase's transformers to [transformers]. 202 /// Set this phase's transformers to [transformers].
199 void updateTransformers(Iterable transformers) { 203 void updateTransformers(Iterable transformers) {
200 _onDirtyController.add(null); 204 _onDirtyController.add(null);
201 205
202 var actualTransformers = transformers.where((op) => op is Transformer); 206 var actualTransformers = transformers.where((op) => op is Transformer);
203 _transformers.clear(); 207 _transformers.clear();
204 _transformers.addAll(actualTransformers); 208 _transformers.addAll(actualTransformers);
(...skipping 16 matching lines...) Expand all
221 for (var input in _inputs.values) { 225 for (var input in _inputs.values) {
222 runner.addInput(input.input); 226 runner.addInput(input.input);
223 } 227 }
224 } 228 }
225 229
226 for (var forwarder in _forwarders.values) { 230 for (var forwarder in _forwarders.values) {
227 forwarder.numChannels = _groups.length + 1; 231 forwarder.numChannels = _groups.length + 1;
228 } 232 }
229 } 233 }
230 234
235 /// Force all [LazyTransformer]s' transforms in this phase to begin producing
236 /// concrete assets.
237 void forceAllTransforms() {
238 for (var group in _groups.values) {
239 group.forceAllTransforms();
240 }
241
242 for (var input in _inputs.values) {
243 input.forceAllTransforms();
244 }
245 }
246
231 /// Add a new phase after this one with [transformers]. 247 /// Add a new phase after this one with [transformers].
232 /// 248 ///
233 /// This may only be called on a phase with no phase following it. 249 /// This may only be called on a phase with no phase following it.
234 Phase addPhase(Iterable transformers) { 250 Phase addPhase(Iterable transformers) {
235 assert(_next == null); 251 assert(_next == null);
236 _next = new Phase._(cascade, transformers, _location, _index + 1); 252 _next = new Phase._(cascade, transformers, _location, _index + 1);
237 for (var output in _outputs.values.toList()) { 253 for (var output in _outputs.values.toList()) {
238 // Remove [output]'s listeners because now they should get the asset from 254 // Remove [output]'s listeners because now they should get the asset from
239 // [_next], rather than this phase. Any transforms consuming [output] will 255 // [_next], rather than this phase. Any transforms consuming [output] will
240 // be re-run and will consume the output from the new final phase. 256 // be re-run and will consume the output from the new final phase.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 _outputs[asset.id] = new PhaseOutput(this, asset, "$_location.$_index"); 333 _outputs[asset.id] = new PhaseOutput(this, asset, "$_location.$_index");
318 _outputs[asset.id].onAsset.listen((output) { 334 _outputs[asset.id].onAsset.listen((output) {
319 if (_next != null) _next.addInput(output); 335 if (_next != null) _next.addInput(output);
320 }, onDone: () => _outputs.remove(asset.id)); 336 }, onDone: () => _outputs.remove(asset.id));
321 if (_next != null) _next.addInput(_outputs[asset.id].output); 337 if (_next != null) _next.addInput(_outputs[asset.id].output);
322 } 338 }
323 } 339 }
324 340
325 String toString() => "phase $_location.$_index"; 341 String toString() => "phase $_location.$_index";
326 } 342 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/package_graph.dart ('k') | pkg/barback/lib/src/phase_input.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698