| OLD | NEW |
| 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 'transform_node.dart'; | 12 import 'transform_node.dart'; |
| 13 import 'utils.dart'; |
| 13 | 14 |
| 14 /// 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. |
| 15 /// | 16 /// |
| 16 /// 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 |
| 17 /// an [onStateChange] stream that emits an event whenever it changes state. | 18 /// an [onStateChange] stream that emits an event whenever it changes state. |
| 18 /// | 19 /// |
| 19 /// Asset nodes are controlled using [AssetNodeController]s. | 20 /// Asset nodes are controlled using [AssetNodeController]s. |
| 20 class AssetNode { | 21 class AssetNode { |
| 21 /// The id of the asset that this node represents. | 22 /// The id of the asset that this node represents. |
| 22 final AssetId id; | 23 final AssetId id; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 }); | 119 }); |
| 119 } | 120 } |
| 120 | 121 |
| 121 /// Calls [callback] as soon as the node is in a state that matches [test]. | 122 /// Calls [callback] as soon as the node is in a state that matches [test]. |
| 122 /// | 123 /// |
| 123 /// [callback] is called synchronously if this is already in such a state. | 124 /// [callback] is called synchronously if this is already in such a state. |
| 124 /// | 125 /// |
| 125 /// The return value of [callback] is piped to the returned Future. | 126 /// The return value of [callback] is piped to the returned Future. |
| 126 Future _waitForState(bool test(AssetState state), | 127 Future _waitForState(bool test(AssetState state), |
| 127 callback(AssetState state)) { | 128 callback(AssetState state)) { |
| 128 if (test(state)) return new Future.sync(() => callback(state)); | 129 if (test(state)) return syncFuture(() => callback(state)); |
| 129 return onStateChange.firstWhere(test).then((_) => callback(state)); | 130 return onStateChange.firstWhere(test).then((_) => callback(state)); |
| 130 } | 131 } |
| 131 | 132 |
| 132 AssetNode._(this.id, this._transform, this._origin) | 133 AssetNode._(this.id, this._transform, this._origin) |
| 133 : _state = AssetState.DIRTY; | 134 : _state = AssetState.DIRTY; |
| 134 | 135 |
| 135 AssetNode._available(Asset asset, this._transform, this._origin) | 136 AssetNode._available(Asset asset, this._transform, this._origin) |
| 136 : id = asset.id, | 137 : id = asset.id, |
| 137 _asset = asset, | 138 _asset = asset, |
| 138 _state = AssetState.AVAILABLE; | 139 _state = AssetState.AVAILABLE; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 225 |
| 225 /// Whether this state is [AssetState.DIRTY]. | 226 /// Whether this state is [AssetState.DIRTY]. |
| 226 bool get isDirty => this == AssetState.DIRTY; | 227 bool get isDirty => this == AssetState.DIRTY; |
| 227 | 228 |
| 228 final String name; | 229 final String name; |
| 229 | 230 |
| 230 const AssetState._(this.name); | 231 const AssetState._(this.name); |
| 231 | 232 |
| 232 String toString() => name; | 233 String toString() => name; |
| 233 } | 234 } |
| OLD | NEW |