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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/pub/asset/dart/serialize/transformer.dart
diff --git a/sdk/lib/_internal/pub/asset/dart/serialize/transformer.dart b/sdk/lib/_internal/pub/asset/dart/serialize/transformer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..608eaa73617a4117e16a356e496aef7a984f8ed3
--- /dev/null
+++ b/sdk/lib/_internal/pub/asset/dart/serialize/transformer.dart
@@ -0,0 +1,60 @@
+// 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 pub.asset.serialize.transformer;
+
+import 'dart:isolate';
+
+import 'package:barback/barback.dart';
+// TODO(nweiz): don't import from "src" once issue 14966 is fixed.
+import 'package:barback/src/internal_asset.dart';
+
+import '../serialize.dart';
+import 'transform.dart';
+
+/// Converts [transformer] into a serializable map.
+Map serializeTransformer(Transformer transformer) {
+ var port = new ReceivePort();
+ port.listen((wrappedMessage) {
+ respond(wrappedMessage, (message) {
+ if (message['type'] == 'isPrimary') {
+ return transformer.isPrimary(deserializeAsset(message['asset']));
+ } else {
+ assert(message['type'] == 'apply');
+
+ // Make sure we return null so that if the transformer's [apply] returns
+ // a non-serializable value it doesn't cause problems.
+ return transformer.apply(
+ new ForeignTransform(message['transform'])).then((_) => null);
+ }
+ });
+ });
+
+ return {
+ 'type': 'Transformer',
+ 'toString': transformer.toString(),
+ 'port': port.sendPort
+ };
+}
+
+// Converts [group] into a serializable map.
+Map serializeTransformerGroup(TransformerGroup group) {
+ return {
+ 'type': 'TransformerGroup',
+ 'toString': group.toString(),
+ 'phases': group.phases.map((phase) {
+ return phase.map(serializeTransformerOrGroup).toList();
+ }).toList()
+ };
+}
+
+/// Converts [transformerOrGroup] into a serializable map.
+Map serializeTransformerOrGroup(transformerOrGroup) {
+ if (transformerOrGroup is Transformer) {
+ return serializeTransformer(transformerOrGroup);
+ } else {
+ assert(transformerOrGroup is TransformerGroup);
+ return serializeTransformerGroup(transformerOrGroup);
+ }
+}
« 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