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

Unified Diff: pkg/barback/lib/src/asset/asset_node_set.dart

Issue 267393009: Transition barback's infrastructure to an aggregate-based model. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/barback/lib/src/asset/asset_set.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/asset/asset_node_set.dart
diff --git a/pkg/barback/lib/src/asset/asset_node_set.dart b/pkg/barback/lib/src/asset/asset_node_set.dart
index 4474866553473ea96eb5754b27e51044a5527178..a1fc17bebcc9952dd07c2e10173244f2b4dd4afb 100644
--- a/pkg/barback/lib/src/asset/asset_node_set.dart
+++ b/pkg/barback/lib/src/asset/asset_node_set.dart
@@ -6,19 +6,37 @@ library barback.asset.asset_node_set;
import 'package:collection/collection.dart';
+import 'asset_id.dart';
import 'asset_node.dart';
/// A set of [AssetNode]s that automatically ensures that nodes are removed from
/// the set as soon as they're marked as [AssetState.REMOVED].
+///
+/// Asset nodes may be accessed by their ids. This means that only one node with
+/// a given id may be stored in the set at a time.
class AssetNodeSet extends DelegatingSet<AssetNode> {
+ // TODO(nweiz): Use DelegatingMapSet when issue 18705 is fixed.
+ /// A map from asset ids to assets in the set.
+ final _assetsById = new Map<AssetId, AssetNode>();
+
AssetNodeSet()
: super(new Set());
+ /// Returns the asset node in the set with [id], or `null` if none exists.
+ AssetNode operator [](AssetId id) => _assetsById[id];
+
bool add(AssetNode node) {
if (node.state.isRemoved) return false;
- node.whenRemoved(() => super.remove(node));
+ node.whenRemoved(() {
+ super.remove(node);
+ _assetsById.remove(node.id);
+ });
+ _assetsById[node.id] = node;
return super.add(node);
}
+ /// Returns whether an asset node with the given [id] is in the set.
+ bool containsId(AssetId id) => _assetsById.containsKey(id);
+
void addAll(Iterable<AssetNode> nodes) => nodes.forEach(add);
}
« no previous file with comments | « no previous file | pkg/barback/lib/src/asset/asset_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698