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

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

Issue 22961002: Add more metadata to non-programmatic barback exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Small fix 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 | « pkg/barback/lib/src/asset_cascade.dart ('k') | pkg/barback/lib/src/build_result.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_node; 5 library barback.asset_node;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'asset.dart'; 9 import 'asset.dart';
10 import 'asset_id.dart'; 10 import 'asset_id.dart';
11 import 'errors.dart'; 11 import 'errors.dart';
12 import 'phase.dart'; 12 import 'phase.dart';
13 import 'transform_node.dart'; 13 import 'transform_node.dart';
14 14
15 /// Describes the current state of an asset as part of a transformation graph. 15 /// Describes the current state of an asset as part of a transformation graph.
16 /// 16 ///
17 /// An asset node can be in one of three states (see [AssetState]). It provides 17 /// An asset node can be in one of three states (see [AssetState]). It provides
18 /// an [onStateChange] stream that emits an event whenever it changes state. 18 /// an [onStateChange] stream that emits an event whenever it changes state.
19 /// 19 ///
20 /// Asset nodes are controlled using [AssetNodeController]s. 20 /// Asset nodes are controlled using [AssetNodeController]s.
21 class AssetNode { 21 class AssetNode {
22 /// The id of the asset that this node represents. 22 /// The id of the asset that this node represents.
23 final AssetId id; 23 final AssetId id;
24 24
25 /// The transform that created this asset node.
26 ///
27 /// This is `null` for source assets.
28 final TransformNode transform;
29
25 /// The current state of the asset node. 30 /// The current state of the asset node.
26 AssetState get state => _state; 31 AssetState get state => _state;
27 AssetState _state; 32 AssetState _state;
28 33
29 /// The concrete asset that this node represents. 34 /// The concrete asset that this node represents.
30 /// 35 ///
31 /// This is null unless [state] is [AssetState.AVAILABLE]. 36 /// This is null unless [state] is [AssetState.AVAILABLE].
32 Asset get asset => _asset; 37 Asset get asset => _asset;
33 Asset _asset; 38 Asset _asset;
34 39
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 104
100 /// Returns a Future that completes as soon as the node is in a state that 105 /// Returns a Future that completes as soon as the node is in a state that
101 /// matches [test]. 106 /// matches [test].
102 /// 107 ///
103 /// The Future completes synchronously if this is already in such a state. 108 /// The Future completes synchronously if this is already in such a state.
104 Future<AssetState> _waitForState(bool test(AssetState state)) { 109 Future<AssetState> _waitForState(bool test(AssetState state)) {
105 if (test(state)) return new Future.sync(() => state); 110 if (test(state)) return new Future.sync(() => state);
106 return onStateChange.firstWhere(test); 111 return onStateChange.firstWhere(test);
107 } 112 }
108 113
109 AssetNode._(this.id) 114 AssetNode._(this.id, this.transform)
110 : _state = AssetState.DIRTY; 115 : _state = AssetState.DIRTY;
111 116
112 AssetNode._available(Asset asset) 117 AssetNode._available(Asset asset, this.transform)
113 : id = asset.id, 118 : id = asset.id,
114 _asset = asset, 119 _asset = asset,
115 _state = AssetState.AVAILABLE; 120 _state = AssetState.AVAILABLE;
116 } 121 }
117 122
118 /// The controller for an [AssetNode]. 123 /// The controller for an [AssetNode].
119 /// 124 ///
120 /// This controls which state the node is in. 125 /// This controls which state the node is in.
121 class AssetNodeController { 126 class AssetNodeController {
122 final AssetNode node; 127 final AssetNode node;
123 128
124 /// Creates a controller for a dirty node. 129 /// Creates a controller for a dirty node.
125 AssetNodeController(AssetId id) 130 AssetNodeController(AssetId id, [TransformNode transform])
126 : node = new AssetNode._(id); 131 : node = new AssetNode._(id, transform);
127 132
128 /// Creates a controller for an available node with the given concrete 133 /// Creates a controller for an available node with the given concrete
129 /// [asset]. 134 /// [asset].
130 AssetNodeController.available(Asset asset) 135 AssetNodeController.available(Asset asset, [TransformNode transform])
131 : node = new AssetNode._available(asset); 136 : node = new AssetNode._available(asset, transform);
132 137
133 /// Marks the node as [AssetState.DIRTY]. 138 /// Marks the node as [AssetState.DIRTY].
134 void setDirty() { 139 void setDirty() {
135 assert(node._state != AssetState.REMOVED); 140 assert(node._state != AssetState.REMOVED);
136 node._state = AssetState.DIRTY; 141 node._state = AssetState.DIRTY;
137 node._asset = null; 142 node._asset = null;
138 node._stateChangeController.add(AssetState.DIRTY); 143 node._stateChangeController.add(AssetState.DIRTY);
139 } 144 }
140 145
141 /// Marks the node as [AssetState.REMOVED]. 146 /// Marks the node as [AssetState.REMOVED].
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 192
188 /// Whether this state is [AssetState.DIRTY]. 193 /// Whether this state is [AssetState.DIRTY].
189 bool get isDirty => this == AssetState.DIRTY; 194 bool get isDirty => this == AssetState.DIRTY;
190 195
191 final String name; 196 final String name;
192 197
193 const AssetState._(this.name); 198 const AssetState._(this.name);
194 199
195 String toString() => name; 200 String toString() => name;
196 } 201 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/asset_cascade.dart ('k') | pkg/barback/lib/src/build_result.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698