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

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

Issue 149243009: Add support for lazy transformers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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/transform.dart
diff --git a/pkg/barback/lib/src/transform.dart b/pkg/barback/lib/src/transform.dart
index 7f0d217b072f1fd34f03ca87fc5d6b08f86af3ea..26b718d0f47d68a032c19eb351c59ff123400e96 100644
--- a/pkg/barback/lib/src/transform.dart
+++ b/pkg/barback/lib/src/transform.dart
@@ -1,35 +1,14 @@
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2014, 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.transform;
-import 'dart:async';
-import 'dart:convert';
-
-import 'package:source_maps/span.dart';
-
import 'asset.dart';
-import 'asset_id.dart';
-import 'asset_node.dart';
import 'asset_set.dart';
-import 'errors.dart';
-import 'log.dart';
+import 'base_transform.dart';
import 'transform_logger.dart';
import 'transform_node.dart';
-import 'utils.dart';
-
-typedef void LogFunction(AssetId asset, LogLevel level, String message,
- Span span);
-
-/// Creates a [Transform] by forwarding to the private constructor.
-///
-/// Lets [TransformNode] create [Transforms] without giving a [Transform]
-/// itself a public constructor, which would be visible to external users.
-/// Unlike the [Transform] class, this function is not exported by barback.dart.
-Transform createTransform(TransformNode node, AssetSet outputs,
- LogFunction logFunction) =>
- new Transform._(node, outputs, logFunction);
/// While a [Transformer] represents a *kind* of transformation, this defines
/// one specific usage of it on a set of files.
@@ -38,65 +17,11 @@ Transform createTransform(TransformNode node, AssetSet outputs,
/// facilitate communication between the [Transformer] and the code hosting
/// the transformation. It lets the [Transformer] access inputs and generate
/// outputs.
-class Transform {
- final TransformNode _node;
- final TransformLogger _logger;
+class Transform extends BaseTransform {
final AssetSet _outputs;
- /// A logger so that the [Transformer] can report build details.
- TransformLogger get logger => _logger;
-
- /// Gets the primary input asset.
- ///
- /// While a transformation can use multiple input assets, one must be a
- /// special "primary" asset. This will be the "entrypoint" or "main" input
- /// file for a transformation.
- ///
- /// For example, with a dart2js transform, the primary input would be the
- /// entrypoint Dart file. All of the other Dart files that that imports
- /// would be secondary inputs.
- ///
- /// This method may fail at runtime if called asynchronously after the
- /// transform begins running. The primary input may become unavailable while
- /// this transformer is running due to asset changes earlier in the graph.
- /// You can ignore the error if this happens: the transformer will be re-run
- /// automatically for you.
- Asset get primaryInput {
- if (_node.primary.state != AssetState.AVAILABLE) {
- throw new AssetNotFoundException(_node.primary.id);
- }
-
- return _node.primary.asset;
- }
-
- Transform._(this._node, this._outputs, LogFunction logFunction)
- : _logger = new TransformLogger(logFunction);
-
- /// Gets the asset for an input [id].
- ///
- /// If an input with that ID cannot be found, throws an
- /// [AssetNotFoundException].
- Future<Asset> getInput(AssetId id) => _node.getInput(id);
-
- /// A convenience method to the contents of the input with [id] as a string.
- ///
- /// This is equivalent to calling `getInput()` followed by `readAsString()`.
- ///
- /// If the asset was created from a [String] the original string is always
- /// returned and [encoding] is ignored. Otherwise, the binary data of the
- /// asset is decoded using [encoding], which defaults to [UTF8].
- Future<String> readInputAsString(AssetId id, {Encoding encoding}) {
- if (encoding == null) encoding = UTF8;
- return getInput(id).then((input) => input.readAsString(encoding: encoding));
- }
-
- /// A convenience method to the contents of the input with [id].
- ///
- /// This is equivalent to calling `getInput()` followed by `read()`.
- ///
- /// If the asset was created from a [String], this returns its UTF-8 encoding.
- Stream<List<int>> readInput(AssetId id) =>
- futureStream(getInput(id).then((input) => input.read()));
+ Transform(TransformNode node, this._outputs, LogFunction logFunction)
Bob Nystrom 2014/01/30 19:33:44 Transform is in barback's public API, but Transfor
nweiz 2014/01/31 03:43:27 In general I prefer exposing constructors that are
+ : super(node, logFunction);
/// Stores [output] as the output created by this transformation.
///

Powered by Google App Engine
This is Rietveld 408576698