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

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

Issue 21446002: Add events in barback to bubble up the dirty bit. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Close TransformNode.onDirty. Created 7 years, 4 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 | « no previous file | pkg/barback/lib/src/phase.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.asset_cascade; 5 library barback.asset_cascade;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:stack_trace/stack_trace.dart'; 10 import 'package:stack_trace/stack_trace.dart';
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 var phases = transformerPhases.toList(); 96 var phases = transformerPhases.toList();
97 97
98 // Each phase writes its outputs as inputs to the next phase after it. 98 // Each phase writes its outputs as inputs to the next phase after it.
99 // Add a phase at the end for the final outputs of the last phase. 99 // Add a phase at the end for the final outputs of the last phase.
100 phases.add([]); 100 phases.add([]);
101 101
102 Phase nextPhase = null; 102 Phase nextPhase = null;
103 for (var transformers in phases.reversed) { 103 for (var transformers in phases.reversed) {
104 nextPhase = new Phase(this, _phases.length, transformers.toList(), 104 nextPhase = new Phase(this, _phases.length, transformers.toList(),
105 nextPhase); 105 nextPhase);
106 nextPhase.onDirty.listen((_) {
107 _newChanges = true;
108 _waitForProcess();
109 });
106 _phases.insert(0, nextPhase); 110 _phases.insert(0, nextPhase);
107 } 111 }
108 } 112 }
109 113
110 /// Gets the asset identified by [id]. 114 /// Gets the asset identified by [id].
111 /// 115 ///
112 /// If [id] is for a generated or transformed asset, this will wait until 116 /// If [id] is for a generated or transformed asset, this will wait until
113 /// it has been created and return it. If the asset cannot be found, throws 117 /// it has been created and return it. If the asset cannot be found, throws
114 /// [AssetNotFoundException]. 118 /// [AssetNotFoundException].
115 Future<Asset> getAssetById(AssetId id) { 119 Future<Asset> getAssetById(AssetId id) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 162
159 return null; 163 return null;
160 } 164 }
161 165
162 /// Adds [sources] to the graph's known set of source assets. 166 /// Adds [sources] to the graph's known set of source assets.
163 /// 167 ///
164 /// Begins applying any transforms that can consume any of the sources. If a 168 /// Begins applying any transforms that can consume any of the sources. If a
165 /// given source is already known, it is considered modified and all 169 /// given source is already known, it is considered modified and all
166 /// transforms that use it will be re-applied. 170 /// transforms that use it will be re-applied.
167 void updateSources(Iterable<AssetId> sources) { 171 void updateSources(Iterable<AssetId> sources) {
168 _newChanges = true;
169
170 for (var id in sources) { 172 for (var id in sources) {
171 var controller = _sourceControllerMap[id]; 173 var controller = _sourceControllerMap[id];
172 if (controller != null) { 174 if (controller != null) {
173 controller.setDirty(); 175 controller.setDirty();
174 } else { 176 } else {
175 _sourceControllerMap[id] = new AssetNodeController(id); 177 _sourceControllerMap[id] = new AssetNodeController(id);
176 _phases.first.addInput(_sourceControllerMap[id].node); 178 _phases.first.addInput(_sourceControllerMap[id].node);
177 } 179 }
178 180
179 // If this source was already loading, cancel the old load, since it may 181 // If this source was already loading, cancel the old load, since it may
180 // return out-of-date contents for the asset. 182 // return out-of-date contents for the asset.
181 if (_loadingSources.containsKey(id)) _loadingSources[id].cancel(); 183 if (_loadingSources.containsKey(id)) _loadingSources[id].cancel();
182 184
183 _loadingSources[id] = 185 _loadingSources[id] =
184 new CancelableFuture<Asset>(_graph.provider.getAsset(id)); 186 new CancelableFuture<Asset>(_graph.provider.getAsset(id));
185 _loadingSources[id].whenComplete(() { 187 _loadingSources[id].whenComplete(() {
186 _loadingSources.remove(id); 188 _loadingSources.remove(id);
187 }).then((asset) { 189 }).then((asset) {
188 var controller = _sourceControllerMap[id].setAvailable(asset); 190 var controller = _sourceControllerMap[id].setAvailable(asset);
189 }).catchError((error) { 191 }).catchError((error) {
190 reportError(error); 192 reportError(error);
191 193
192 // TODO(nweiz): propagate error information through asset nodes. 194 // TODO(nweiz): propagate error information through asset nodes.
193 _sourceControllerMap.remove(id).setRemoved(); 195 _sourceControllerMap.remove(id).setRemoved();
194 }); 196 });
195 } 197 }
196
197 _waitForProcess();
198 } 198 }
199 199
200 /// Removes [removed] from the graph's known set of source assets. 200 /// Removes [removed] from the graph's known set of source assets.
201 void removeSources(Iterable<AssetId> removed) { 201 void removeSources(Iterable<AssetId> removed) {
202 _newChanges = true;
203
204 removed.forEach((id) { 202 removed.forEach((id) {
205 // If the source was being loaded, cancel that load. 203 // If the source was being loaded, cancel that load.
206 if (_loadingSources.containsKey(id)) _loadingSources.remove(id).cancel(); 204 if (_loadingSources.containsKey(id)) _loadingSources.remove(id).cancel();
207 205
208 var controller = _sourceControllerMap.remove(id); 206 var controller = _sourceControllerMap.remove(id);
209 // Don't choke if an id is double-removed for some reason. 207 // Don't choke if an id is double-removed for some reason.
210 if (controller != null) controller.setRemoved(); 208 if (controller != null) controller.setRemoved();
211 }); 209 });
212
213 _waitForProcess();
214 } 210 }
215 211
216 void reportError(error) { 212 void reportError(error) {
217 _accumulatedErrors.add(error); 213 _accumulatedErrors.add(error);
218 _errorsController.add(error); 214 _errorsController.add(error);
219 } 215 }
220 216
221 /// Starts the build process asynchronously if there is work to be done. 217 /// Starts the build process asynchronously if there is work to be done.
222 /// 218 ///
223 /// Returns a future that completes with the background processing is done. 219 /// Returns a future that completes with the background processing is done.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 msg.write(prefixLines(error.toString())); 305 msg.write(prefixLines(error.toString()));
310 if (stackTrace != null) { 306 if (stackTrace != null) {
311 msg.write("\n\n"); 307 msg.write("\n\n");
312 msg.write("Stack trace:\n"); 308 msg.write("Stack trace:\n");
313 msg.write(prefixLines(stackTrace.toString())); 309 msg.write(prefixLines(stackTrace.toString()));
314 } 310 }
315 return msg.toString(); 311 return msg.toString();
316 }).join("\n\n"); 312 }).join("\n\n");
317 } 313 }
318 } 314 }
OLDNEW
« no previous file with comments | « no previous file | pkg/barback/lib/src/phase.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698