OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.graph.static_asset_cascade; | 5 library barback.graph.static_asset_cascade; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
| 9 import 'package:async/async.dart'; |
| 10 import 'package:collection/collection.dart'; |
| 11 |
9 import '../asset/asset_id.dart'; | 12 import '../asset/asset_id.dart'; |
10 import '../asset/asset_node.dart'; | 13 import '../asset/asset_node.dart'; |
11 import '../asset/asset_set.dart'; | 14 import '../asset/asset_set.dart'; |
12 import '../errors.dart'; | 15 import '../errors.dart'; |
13 import '../log.dart'; | 16 import '../log.dart'; |
14 import '../package_provider.dart'; | 17 import '../package_provider.dart'; |
15 import 'asset_cascade.dart'; | 18 import 'asset_cascade.dart'; |
16 import 'node_status.dart'; | 19 import 'node_status.dart'; |
17 import 'package_graph.dart'; | 20 import 'package_graph.dart'; |
18 | 21 |
(...skipping 12 matching lines...) Expand all Loading... |
31 | 34 |
32 StaticAssetCascade(this.graph, this.package); | 35 StaticAssetCascade(this.graph, this.package); |
33 | 36 |
34 Stream<BarbackException> get errors => _errorsController.stream; | 37 Stream<BarbackException> get errors => _errorsController.stream; |
35 final _errorsController = | 38 final _errorsController = |
36 new StreamController<BarbackException>.broadcast(sync: true); | 39 new StreamController<BarbackException>.broadcast(sync: true); |
37 | 40 |
38 final status = NodeStatus.IDLE; | 41 final status = NodeStatus.IDLE; |
39 | 42 |
40 final onLog = new StreamController<LogEntry>.broadcast().stream; | 43 final onLog = new StreamController<LogEntry>.broadcast().stream; |
41 final onStatusChange = new StreamController<LogEntry>.broadcast().stream; | 44 final onStatusChange = new StreamController<NodeStatus>.broadcast().stream; |
42 final onAsset = new StreamController<AssetNode>.broadcast().stream; | 45 final onAsset = new StreamController<AssetNode>.broadcast().stream; |
43 | 46 |
44 Future<AssetSet> get availableOutputs { | 47 Future<AssetSet> get availableOutputs { |
45 var provider = graph.provider as StaticPackageProvider; | 48 var provider = graph.provider as StaticPackageProvider; |
46 return provider.getAllAssetIds(package).asyncMap(provider.getAsset).toList() | 49 return provider.getAllAssetIds(package).asyncMap(provider.getAsset).toList() |
47 .then((assets) => new AssetSet.from(assets)); | 50 .then((assets) => new AssetSet.from(DelegatingList.typed(assets))); |
48 } | 51 } |
49 | 52 |
50 Future<AssetNode> getAssetNode(AssetId id) { | 53 Future<AssetNode> getAssetNode(AssetId id) { |
51 return _sources.putIfAbsent(id, () { | 54 return _sources.putIfAbsent(id, () { |
52 return graph.provider.getAsset(id).then((asset) { | 55 return DelegatingFuture.typed(graph.provider.getAsset(id).then((asset) { |
53 return new AssetNodeController.available(asset).node; | 56 return new AssetNodeController.available(asset).node; |
54 }).catchError((error, stackTrace) { | 57 }).catchError((error, stackTrace) { |
55 if (error is! AssetNotFoundException) { | 58 if (error is! AssetNotFoundException) { |
56 reportError(new AssetLoadException(id, error, stackTrace)); | 59 reportError(new AssetLoadException(id, error, stackTrace)); |
57 } | 60 } |
58 | 61 |
59 // TODO(nweiz): propagate error information through asset nodes. | 62 // TODO(nweiz): propagate error information through asset nodes. |
60 return null; | 63 return null; |
61 }); | 64 })); |
62 }); | 65 }); |
63 } | 66 } |
64 | 67 |
65 void updateSources(Iterable<AssetId> sources) => | 68 void updateSources(Iterable<AssetId> sources) => |
66 throw new UnsupportedError("Static package $package can't be explicitly " | 69 throw new UnsupportedError("Static package $package can't be explicitly " |
67 "provided sources."); | 70 "provided sources."); |
68 | 71 |
69 void removeSources(Iterable<AssetId> sources) => | 72 void removeSources(Iterable<AssetId> sources) => |
70 throw new UnsupportedError("Static package $package can't be explicitly " | 73 throw new UnsupportedError("Static package $package can't be explicitly " |
71 "provided sources."); | 74 "provided sources."); |
72 | 75 |
73 void updateTransformers(Iterable<Iterable> transformersIterable) => | 76 void updateTransformers(Iterable<Iterable> transformersIterable) => |
74 throw new UnsupportedError("Static package $package can't have " | 77 throw new UnsupportedError("Static package $package can't have " |
75 "transformers."); | 78 "transformers."); |
76 | 79 |
77 void forceAllTransforms() {} | 80 void forceAllTransforms() {} |
78 | 81 |
79 void reportError(BarbackException error) => _errorsController.add(error); | 82 void reportError(BarbackException error) => _errorsController.add(error); |
80 | 83 |
81 String toString() => "static cascade for $package"; | 84 String toString() => "static cascade for $package"; |
82 } | 85 } |
OLD | NEW |