Chromium Code Reviews| OLD | NEW |
|---|---|
| (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.barback; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'asset.dart'; | |
| 10 import 'asset_id.dart'; | |
| 11 import 'asset_cascade.dart'; | |
| 12 import 'package_graph.dart'; | |
| 13 import 'package_provider.dart'; | |
| 14 | |
| 15 /// A general purpose asynchronous build dependency graph manager. | |
|
nweiz
2013/07/25 22:58:58
"General purpose" should be hyphenated.
I want a
Bob Nystrom
2013/07/26 20:20:11
Done.
| |
| 16 /// | |
| 17 /// You give barback a [PackageProvider] which can yield a set of [Transformer]s | |
| 18 /// and raw source [Asset]s. Then you add input files to the system by calling | |
|
nweiz
2013/07/25 22:58:58
"input files to the system" is confusing. [updateS
Bob Nystrom
2013/07/26 20:20:11
Done.
| |
| 19 /// [updateSources]. Barback will automatically wire up the appropriate | |
| 20 /// transformers to those inputs and start running them asynchronously. If the | |
|
nweiz
2013/07/25 22:58:58
"the transformer" -> "a transformer"
Bob Nystrom
2013/07/26 20:20:11
Done.
| |
| 21 /// transformer produces outputs that can be consumed by other transformers, | |
| 22 /// they will automatically be pipelined correctly. | |
| 23 /// | |
| 24 /// You can then request assets (either source or generated) by calling | |
| 25 /// [getAssetById]. This will wait for any necessary transformations and then | |
| 26 /// return the asset. | |
| 27 /// | |
| 28 /// When source files have been modified or removed, tell barback by calling | |
| 29 /// [updateSources] and [removeSources] as appropriate. Barback will | |
| 30 /// automatically track which transformations are affected by those changes and | |
| 31 /// re-run them as needed. | |
| 32 /// | |
| 33 /// Barback tries to be resilient to errors since assets are often in an | |
| 34 /// in-progress state. When errors occur, they will be captured and emitted on | |
| 35 /// the [errors] stream. | |
| 36 class Barback { | |
| 37 /// The graph managed by this instance. | |
| 38 final PackageGraph _graph; | |
| 39 | |
| 40 /// A stream that emits a [BuildResult] each time the build is completed, | |
| 41 /// whether or not it succeeded. | |
| 42 /// | |
| 43 /// This will emit a result only once every package's [AssetCascade] has | |
| 44 /// finished building. | |
| 45 /// | |
| 46 /// If an unexpected error in barback itself occurs, it will be emitted | |
| 47 /// through this stream's error channel. | |
| 48 Stream<BuildResult> get results => _graph.results; | |
| 49 | |
| 50 /// A stream that emits any errors from the graph or the transformers. | |
| 51 /// | |
| 52 /// This emits errors as they're detected. If an error occurs in one part of | |
| 53 /// the graph, unrelated parts will continue building. | |
| 54 /// | |
| 55 /// This will not emit programming errors from barback itself. Those will be | |
| 56 /// emitted through the [results] stream's error channel. | |
| 57 Stream get errors => _graph.errors; | |
| 58 | |
| 59 Barback(PackageProvider provider) | |
| 60 : _graph = new PackageGraph(provider); | |
| 61 | |
| 62 /// Gets the asset identified by [id]. | |
| 63 /// | |
| 64 /// If [id] is for a generated or transformed asset, this will wait until | |
| 65 /// it has been created and return it. If the asset cannot be found, throws | |
| 66 /// [AssetNotFoundException]. | |
| 67 Future<Asset> getAssetById(AssetId id) => _graph.getAssetById(id); | |
| 68 | |
| 69 /// Adds [sources] to the graph's known set of source assets. | |
| 70 /// | |
| 71 /// Begins applying any transforms that can consume any of the sources. If a | |
| 72 /// given source is already known, it is considered modified and all | |
| 73 /// transforms that use it will be re-applied. | |
| 74 void updateSources(Iterable<AssetId> sources) => | |
| 75 _graph.updateSources(sources); | |
| 76 | |
| 77 /// Removes [removed] from the graph's known set of source assets. | |
| 78 void removeSources(Iterable<AssetId> removed) => | |
| 79 _graph.removeSources(removed); | |
| 80 } | |
| OLD | NEW |