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

Unified Diff: pkg/barback/lib/src/asset_forwarder.dart

Issue 23363002: Factor out an input-handling class from Phase in barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/barback/lib/src/package_provider.dart » ('j') | pkg/barback/lib/src/phase.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/asset_forwarder.dart
diff --git a/pkg/barback/lib/src/asset_forwarder.dart b/pkg/barback/lib/src/asset_forwarder.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2c9d461964592a169469b5f020e5367f3072c873
--- /dev/null
+++ b/pkg/barback/lib/src/asset_forwarder.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library barback.asset_forwarder;
+
+import 'dart:async';
+
+import 'asset_node.dart';
+
+/// A wrapper for an [AssetNode] that forwards events to a new node.
+///
+/// This allows the output node to be marked as removed without the input node
+/// having been removed.
Bob Nystrom 2013/08/21 19:47:38 Without knowing any larger context, this doesn't e
nweiz 2013/08/21 20:33:51 Done.
+class AssetForwarder {
+ /// The subscription on the input node.
+ StreamSubscription _subscription;
+
+ /// The controller for the output node.
+ final AssetNodeController _controller;
+
+ /// The node to which events are forwarded.
+ AssetNode get node => _controller.node;
+
+ AssetForwarder(AssetNode node)
+ : _controller = new AssetNodeController(node.id, node.transform) {
+ _subscription = node.onStateChange.listen((state) {
+ if (state.isAvailable) {
+ _controller.setAvailable(node.asset);
+ } else if (state.isDirty) {
+ _controller.setDirty();
+ } else {
+ assert(state.isRemoved);
+ close();
+ }
+ });
+
+ if (node.state.isAvailable) {
+ _controller.setAvailable(node.asset);
+ } else if (node.state.isRemoved) {
+ close();
+ }
+ }
+
+ /// Closes the forwarder and marks [node] as removed.
+ void close() {
+ if (_controller.node.state.isRemoved) return;
+ _subscription.cancel();
+ _controller.setRemoved();
+ }
+}
« no previous file with comments | « no previous file | pkg/barback/lib/src/package_provider.dart » ('j') | pkg/barback/lib/src/phase.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698