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

Side by Side Diff: sdk/lib/_internal/pub/asset/dart/serialize/transformer.dart

Issue 203913003: Share code between the transformer isolate and pub proper. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
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 pub.asset.serialize.transformer;
6
7 import 'dart:isolate';
8
9 import 'package:barback/barback.dart';
10 // TODO(nweiz): don't import from "src" once issue 14966 is fixed.
11 import 'package:barback/src/internal_asset.dart';
12
13 import '../serialize.dart';
14 import 'transform.dart';
15
16 /// Converts [transformer] into a serializable map.
17 Map serializeTransformer(Transformer transformer) {
18 var port = new ReceivePort();
19 port.listen((wrappedMessage) {
20 respond(wrappedMessage, (message) {
21 if (message['type'] == 'isPrimary') {
22 return transformer.isPrimary(deserializeAsset(message['asset']));
23 } else {
24 assert(message['type'] == 'apply');
25
26 // Make sure we return null so that if the transformer's [apply] returns
27 // a non-serializable value it doesn't cause problems.
28 return transformer.apply(
29 new ForeignTransform(message['transform'])).then((_) => null);
30 }
31 });
32 });
33
34 return {
35 'type': 'Transformer',
36 'toString': transformer.toString(),
37 'port': port.sendPort
38 };
39 }
40
41 // Converts [group] into a serializable map.
42 Map serializeTransformerGroup(TransformerGroup group) {
43 return {
44 'type': 'TransformerGroup',
45 'toString': group.toString(),
46 'phases': group.phases.map((phase) {
47 return phase.map(serializeTransformerOrGroup).toList();
48 }).toList()
49 };
50 }
51
52 /// Converts [transformerOrGroup] into a serializable map.
53 Map serializeTransformerOrGroup(transformerOrGroup) {
54 if (transformerOrGroup is Transformer) {
55 return serializeTransformer(transformerOrGroup);
56 } else {
57 assert(transformerOrGroup is TransformerGroup);
58 return serializeTransformerGroup(transformerOrGroup);
59 }
60 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/asset/dart/serialize/transform.dart ('k') | sdk/lib/_internal/pub/asset/dart/transformer_isolate.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698