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

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

Issue 18650004: Make Assets know their ID. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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.transform_node; 5 library barback.transform_node;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'asset.dart'; 9 import 'asset.dart';
10 import 'asset_graph.dart'; 10 import 'asset_graph.dart';
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 void dirty() { 51 void dirty() {
52 _isDirty = true; 52 _isDirty = true;
53 } 53 }
54 54
55 /// Applies this transform. 55 /// Applies this transform.
56 /// 56 ///
57 /// Returns a [TransformOutputs] describing the resulting outputs compared to 57 /// Returns a [TransformOutputs] describing the resulting outputs compared to
58 /// previous runs. 58 /// previous runs.
59 Future<TransformOutputs> apply() { 59 Future<TransformOutputs> apply() {
60 var newInputs = new Set<AssetNode>(); 60 var newInputs = new Set<AssetNode>();
61 var newOutputs = new Map<AssetId, Asset>(); 61 var newOutputs = new Set<Asset>();
62 var transform = createTransform(this, newInputs, newOutputs); 62 var transform = createTransform(this, newInputs, newOutputs);
63 return _transformer.apply(transform).catchError((error) { 63 return _transformer.apply(transform).catchError((error) {
64 // Catch all transformer errors and pipe them to the results stream. 64 // Catch all transformer errors and pipe them to the results stream.
65 // This is so a broken transformer doesn't take down the whole graph. 65 // This is so a broken transformer doesn't take down the whole graph.
66 phase.graph.reportError(error); 66 phase.graph.reportError(error);
67 67
68 // Don't allow partial results from a failed transform. 68 // Don't allow partial results from a failed transform.
69 newOutputs.clear(); 69 newOutputs.clear();
70 }).then((_) { 70 }).then((_) {
71 _isDirty = false; 71 _isDirty = false;
72 72
73 // Stop watching any inputs that were removed. 73 // Stop watching any inputs that were removed.
74 for (var oldInput in _inputs) { 74 for (var oldInput in _inputs) {
75 oldInput.consumers.remove(this); 75 oldInput.consumers.remove(this);
76 } 76 }
77 77
78 // Watch any new inputs so this transform will be re-processed when an 78 // Watch any new inputs so this transform will be re-processed when an
79 // input is modified. 79 // input is modified.
80 for (var newInput in newInputs) { 80 for (var newInput in newInputs) {
81 newInput.consumers.add(this); 81 newInput.consumers.add(this);
82 } 82 }
83 83
84 _inputs = newInputs; 84 _inputs = newInputs;
85 85
86 // See which outputs are missing from the last run. 86 // See which outputs are missing from the last run.
87 var outputIds = newOutputs.keys.toSet(); 87 var outputIds = newOutputs.map((asset) => asset.id).toSet();
88 var removed = _outputs.difference(outputIds); 88 var removed = _outputs.difference(outputIds);
89 _outputs = outputIds; 89 _outputs = outputIds;
90 90
91 return new TransformOutputs(newOutputs, removed); 91 return new TransformOutputs(newOutputs, removed);
92 }); 92 });
93 } 93 }
94 } 94 }
95 95
96 /// The result of running a [Transform], compared to the previous time it was 96 /// The result of running a [Transform], compared to the previous time it was
97 /// applied. 97 /// applied.
98 class TransformOutputs { 98 class TransformOutputs {
99 /// The outputs that are new or were modified since the last run. 99 /// The outputs that are new or were modified since the last run.
100 final Map<AssetId, Asset> updated; 100 final Set<Asset> updated;
101 101
102 /// The outputs that were created by the previous run but were not generated 102 /// The outputs that were created by the previous run but were not generated
103 /// by the most recent run. 103 /// by the most recent run.
104 final Set<AssetId> removed; 104 final Set<AssetId> removed;
105 105
106 TransformOutputs(this.updated, this.removed); 106 TransformOutputs(this.updated, this.removed);
107 } 107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698