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

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

Issue 178223024: Refactor the Transform classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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
Index: pkg/barback/lib/src/base_transform.dart
diff --git a/pkg/barback/lib/src/base_transform.dart b/pkg/barback/lib/src/base_transform.dart
index 27dc12a3a1c1bf33a0c388eff562956705e98752..d03f4b3a98ceb0cc669e9b9ea420e72fb23fb26f 100644
--- a/pkg/barback/lib/src/base_transform.dart
+++ b/pkg/barback/lib/src/base_transform.dart
@@ -11,6 +11,7 @@ import 'asset.dart';
import 'asset_id.dart';
import 'asset_node.dart';
import 'errors.dart';
+import 'log.dart';
import 'transform_logger.dart';
import 'transform_node.dart';
import 'utils.dart';
@@ -22,10 +23,19 @@ import 'utils.dart';
/// subclasses to provide a means of emitting outputs.
abstract class BaseTransform {
final TransformNode _node;
- final TransformLogger _logger;
+
+ /// The controller for the stream of log entries emitted by the transformer.
+ ///
+ /// This is exposed via [BaseTransformController].
+ ///
+ /// This is synchronous because error logs can cause the transform to fail, so
+ /// we need to ensure that their processing isn't delayed until after the
+ /// transform or build has finished.
+ final _onLogController = new StreamController<LogEntry>.broadcast(sync: true);
/// A logger so that the [Transformer] can report build details.
TransformLogger get logger => _logger;
+ TransformLogger _logger;
/// Gets the primary input asset.
///
@@ -50,8 +60,14 @@ abstract class BaseTransform {
return _node.primary.asset;
}
- BaseTransform(this._node, LogFunction logFunction)
- : _logger = new TransformLogger(logFunction);
+ BaseTransform(this._node) {
+ _logger = new TransformLogger((asset, level, message, span) {
+ // If the log isn't already associated with an asset, use the primary.
+ if (asset == null) asset = _node.primary.id;
+ var entry = new LogEntry(_node.info, asset, level, message, span);
+ _onLogController.add(entry);
+ });
+ }
/// Gets the asset for an input [id].
///
@@ -79,3 +95,26 @@ abstract class BaseTransform {
Stream<List<int>> readInput(AssetId id) =>
futureStream(getInput(id).then((input) => input.read()));
}
+
+/// The base class for controllers of subclasses of [BaseTransform].
+///
+/// Controllers are used so that [TransformNode]s can get values from a
+/// [BaseTransform] without exposing getters in the public API.
+abstract class BaseTransformController {
+ /// The [BaseTransform] controlled by this controller.
+ final BaseTransform transform;
+
+ /// The stream of log entries emitted by the transformer during a run.
+ Stream<LogEntry> get onLog => transform._onLogController.stream;
+
+ BaseTransformController(this.transform);
+
+ /// Notifies the [BaseTransform] that the transformation has finished being
+ /// applied.
+ ///
+ /// This will close any streams and release any resources that were allocated
+ /// for the duration of the transformation.
+ void close() {
+ transform._onLogController.close();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698