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

Side by Side 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: Fix a library name 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library barback.asset_forwarder;
6
7 import 'dart:async';
8
9 import 'asset_node.dart';
10
11 /// A wrapper for an [AssetNode] that forwards events to a new node.
12 ///
13 /// This allows the output node to be marked as removed without the input node
14 /// having been removed.
15 class AssetForwarder {
16 /// The subscription on the input node.
17 StreamSubscription _subscription;
18
19 /// The controller for the output node.
20 final AssetNodeController _controller;
21
22 /// The node to which events are forwarded.
23 AssetNode get node => _controller.node;
24
25 AssetForwarder(AssetNode node)
26 : _controller = new AssetNodeController(node.id, node.transform) {
27 _subscription = node.onStateChange.listen((state) {
28 if (state.isAvailable) {
29 _controller.setAvailable(node.asset);
30 } else if (state.isDirty) {
31 _controller.setDirty();
32 } else {
33 assert(state.isRemoved);
34 close();
35 }
36 });
37
38 if (node.state.isAvailable) {
39 _controller.setAvailable(node.asset);
40 } else if (node.state.isRemoved) {
41 close();
42 }
43 }
44
45 /// Closes the forwarder and marks [node] as removed.
46 void close() {
47 if (_controller.node.state.isRemoved) return;
48 _subscription.cancel();
49 _controller.setRemoved();
50 }
51 }
OLDNEW
« no previous file with comments | « no previous file | pkg/barback/lib/src/package_provider.dart » ('j') | pkg/barback/lib/src/phase_input.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698