OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library pub.asset.serialize.transformer; | 5 library pub.asset.serialize.transformer; |
6 | 6 |
7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
8 | 8 |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 // TODO(nweiz): don't import from "src" once issue 14966 is fixed. | 10 // TODO(nweiz): don't import from "src" once issue 14966 is fixed. |
11 import 'package:barback/src/internal_asset.dart'; | 11 import 'package:barback/src/internal_asset.dart'; |
12 | 12 |
13 import '../serialize.dart'; | 13 import '../serialize.dart'; |
14 import 'transform.dart'; | 14 import 'transform.dart'; |
15 | 15 |
16 /// Converts [transformer] into a serializable map. | 16 /// Converts [transformer] into a serializable map. |
17 Map serializeTransformer(Transformer transformer) { | 17 Map serializeTransformer(Transformer transformer) { |
18 var port = new ReceivePort(); | 18 var port = new ReceivePort(); |
19 port.listen((wrappedMessage) { | 19 port.listen((wrappedMessage) { |
20 respond(wrappedMessage, (message) { | 20 respond(wrappedMessage, (message) { |
21 if (message['type'] == 'isPrimary') { | 21 if (message['type'] == 'isPrimary') { |
22 return transformer.isPrimary(deserializeAsset(message['asset'])); | 22 return transformer.isPrimary(deserializeId(message['id'])); |
23 } else { | 23 } else { |
24 assert(message['type'] == 'apply'); | 24 assert(message['type'] == 'apply'); |
25 | 25 |
26 // Make sure we return null so that if the transformer's [apply] returns | 26 // Make sure we return null so that if the transformer's [apply] returns |
27 // a non-serializable value it doesn't cause problems. | 27 // a non-serializable value it doesn't cause problems. |
28 return transformer.apply( | 28 return transformer.apply( |
29 new ForeignTransform(message['transform'])).then((_) => null); | 29 new ForeignTransform(message['transform'])).then((_) => null); |
30 } | 30 } |
31 }); | 31 }); |
32 }); | 32 }); |
(...skipping 18 matching lines...) Expand all Loading... |
51 | 51 |
52 /// Converts [transformerOrGroup] into a serializable map. | 52 /// Converts [transformerOrGroup] into a serializable map. |
53 Map serializeTransformerOrGroup(transformerOrGroup) { | 53 Map serializeTransformerOrGroup(transformerOrGroup) { |
54 if (transformerOrGroup is Transformer) { | 54 if (transformerOrGroup is Transformer) { |
55 return serializeTransformer(transformerOrGroup); | 55 return serializeTransformer(transformerOrGroup); |
56 } else { | 56 } else { |
57 assert(transformerOrGroup is TransformerGroup); | 57 assert(transformerOrGroup is TransformerGroup); |
58 return serializeTransformerGroup(transformerOrGroup); | 58 return serializeTransformerGroup(transformerOrGroup); |
59 } | 59 } |
60 } | 60 } |
OLD | NEW |