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

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: Tweak doc. 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
« no previous file with comments | « pkg/barback/lib/src/transform.dart ('k') | pkg/barback/lib/src/transformer.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.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';
11 import 'asset_id.dart'; 11 import 'asset_id.dart';
12 import 'asset_node.dart'; 12 import 'asset_node.dart';
13 import 'asset_set.dart';
13 import 'errors.dart'; 14 import 'errors.dart';
14 import 'phase.dart'; 15 import 'phase.dart';
15 import 'transform.dart'; 16 import 'transform.dart';
16 import 'transformer.dart'; 17 import 'transformer.dart';
17 18
18 /// Describes a transform on a set of assets and its relationship to the build 19 /// Describes a transform on a set of assets and its relationship to the build
19 /// dependency graph. 20 /// dependency graph.
20 /// 21 ///
21 /// Keeps track of whether it's dirty and needs to be run and which assets it 22 /// Keeps track of whether it's dirty and needs to be run and which assets it
22 /// depends on. 23 /// depends on.
(...skipping 28 matching lines...) Expand all
51 void dirty() { 52 void dirty() {
52 _isDirty = true; 53 _isDirty = true;
53 } 54 }
54 55
55 /// Applies this transform. 56 /// Applies this transform.
56 /// 57 ///
57 /// Returns a [TransformOutputs] describing the resulting outputs compared to 58 /// Returns a [TransformOutputs] describing the resulting outputs compared to
58 /// previous runs. 59 /// previous runs.
59 Future<TransformOutputs> apply() { 60 Future<TransformOutputs> apply() {
60 var newInputs = new Set<AssetNode>(); 61 var newInputs = new Set<AssetNode>();
61 var newOutputs = new Map<AssetId, Asset>(); 62 var newOutputs = new AssetSet();
62 var transform = createTransform(this, newInputs, newOutputs); 63 var transform = createTransform(this, newInputs, newOutputs);
63 return _transformer.apply(transform).catchError((error) { 64 return _transformer.apply(transform).catchError((error) {
64 // Catch all transformer errors and pipe them to the results stream. 65 // 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. 66 // This is so a broken transformer doesn't take down the whole graph.
66 phase.graph.reportError(error); 67 phase.graph.reportError(error);
67 68
68 // Don't allow partial results from a failed transform. 69 // Don't allow partial results from a failed transform.
69 newOutputs.clear(); 70 newOutputs.clear();
70 }).then((_) { 71 }).then((_) {
71 _isDirty = false; 72 _isDirty = false;
72 73
73 // Stop watching any inputs that were removed. 74 // Stop watching any inputs that were removed.
74 for (var oldInput in _inputs) { 75 for (var oldInput in _inputs) {
75 oldInput.consumers.remove(this); 76 oldInput.consumers.remove(this);
76 } 77 }
77 78
78 // Watch any new inputs so this transform will be re-processed when an 79 // Watch any new inputs so this transform will be re-processed when an
79 // input is modified. 80 // input is modified.
80 for (var newInput in newInputs) { 81 for (var newInput in newInputs) {
81 newInput.consumers.add(this); 82 newInput.consumers.add(this);
82 } 83 }
83 84
84 _inputs = newInputs; 85 _inputs = newInputs;
85 86
86 // See which outputs are missing from the last run. 87 // See which outputs are missing from the last run.
87 var outputIds = newOutputs.keys.toSet(); 88 var outputIds = newOutputs.map((asset) => asset.id).toSet();
88 var removed = _outputs.difference(outputIds); 89 var removed = _outputs.difference(outputIds);
89 _outputs = outputIds; 90 _outputs = outputIds;
90 91
91 return new TransformOutputs(newOutputs, removed); 92 return new TransformOutputs(newOutputs, removed);
92 }); 93 });
93 } 94 }
94 } 95 }
95 96
96 /// The result of running a [Transform], compared to the previous time it was 97 /// The result of running a [Transform], compared to the previous time it was
97 /// applied. 98 /// applied.
98 class TransformOutputs { 99 class TransformOutputs {
99 /// The outputs that are new or were modified since the last run. 100 /// The outputs that are new or were modified since the last run.
100 final Map<AssetId, Asset> updated; 101 final AssetSet updated;
101 102
102 /// The outputs that were created by the previous run but were not generated 103 /// The outputs that were created by the previous run but were not generated
103 /// by the most recent run. 104 /// by the most recent run.
104 final Set<AssetId> removed; 105 final Set<AssetId> removed;
105 106
106 TransformOutputs(this.updated, this.removed); 107 TransformOutputs(this.updated, this.removed);
107 } 108 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/transform.dart ('k') | pkg/barback/lib/src/transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698