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

Side by Side Diff: pkg/barback/lib/src/transformer/wrapping_aggregate_transformer.dart

Issue 808713003: Remove barback from the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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
« no previous file with comments | « pkg/barback/lib/src/transformer/transformer_group.dart ('k') | pkg/barback/lib/src/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library barback.transformer.wrapping_aggregate_transformer;
6
7 import 'dart:async';
8
9 import '../asset/asset_id.dart';
10 import '../utils.dart';
11 import 'aggregate_transform.dart';
12 import 'aggregate_transformer.dart';
13 import 'declaring_aggregate_transform.dart';
14 import 'declaring_aggregate_transformer.dart';
15 import 'declaring_transform.dart';
16 import 'declaring_transformer.dart';
17 import 'lazy_aggregate_transformer.dart';
18 import 'lazy_transformer.dart';
19 import 'transform.dart';
20 import 'transformer.dart';
21
22 /// An [AggregateTransformer] that wraps a non-aggregate [Transformer].
23 ///
24 /// Although barback internally works in terms of [AggregateTransformer]s, most
25 /// transformers only work on individual primary inputs in isolation. We want to
26 /// allow those transformers to implement the more user-friendly [Transformer]
27 /// interface. This class makes that possible.
28 class WrappingAggregateTransformer implements AggregateTransformer {
29 /// The wrapped transformer.
30 final Transformer transformer;
31
32 factory WrappingAggregateTransformer(Transformer transformer) {
33 if (transformer is LazyTransformer) {
34 return new _LazyWrappingAggregateTransformer(
35 transformer as LazyTransformer);
36 } else if (transformer is DeclaringTransformer) {
37 return new _DeclaringWrappingAggregateTransformer(
38 transformer as DeclaringTransformer);
39 } else {
40 return new WrappingAggregateTransformer._(transformer);
41 }
42 }
43
44 WrappingAggregateTransformer._(this.transformer);
45
46 Future<String> classifyPrimary(AssetId id) {
47 return syncFuture(() => transformer.isPrimary(id))
48 .then((isPrimary) => isPrimary ? id.path : null);
49 }
50
51 Future apply(AggregateTransform aggregateTransform) {
52 return newTransform(aggregateTransform)
53 .then((transform) => transformer.apply(transform));
54 }
55
56 String toString() => transformer.toString();
57 }
58
59 /// A wrapper for [DeclaringTransformer]s that implements
60 /// [DeclaringAggregateTransformer].
61 class _DeclaringWrappingAggregateTransformer
62 extends WrappingAggregateTransformer
63 implements DeclaringAggregateTransformer {
64 final DeclaringTransformer _declaring;
65
66 _DeclaringWrappingAggregateTransformer(DeclaringTransformer transformer)
67 : _declaring = transformer,
68 super._(transformer as Transformer);
69
70 Future declareOutputs(DeclaringAggregateTransform aggregateTransform) {
71 return newDeclaringTransform(aggregateTransform).then((transform) {
72 return (transformer as DeclaringTransformer).declareOutputs(transform);
73 });
74 }
75 }
76
77 /// A wrapper for [LazyTransformer]s that implements
78 /// [LazyAggregateTransformer].
79 class _LazyWrappingAggregateTransformer
80 extends _DeclaringWrappingAggregateTransformer
81 implements LazyAggregateTransformer {
82 _LazyWrappingAggregateTransformer(LazyTransformer transformer)
83 : super(transformer);
84 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/transformer/transformer_group.dart ('k') | pkg/barback/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698