Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit 03649c0

Browse files
committed
Simplify jsify and dartify
1 parent e41625c commit 03649c0

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

lib/src/interop/js_interop.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ import 'package:js/js.dart';
55

66
@JS("JSON.stringify")
77
external String stringify(obj);
8-
9-
@JS("JSON.parse")
10-
external dynamic parse(s);

lib/src/utils.dart

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:convert';
33

44
import 'package:func/func.dart';
55
import 'package:js/js.dart';
6+
import 'package:js/js_util.dart' as util;
67

78
import 'interop/firebase_interop.dart';
89
import 'interop/js_interop.dart' as js;
@@ -13,6 +14,10 @@ dynamic dartify(Object jsObject) {
1314
return jsObject;
1415
}
1516

17+
if (jsObject is List) {
18+
return jsObject.map(dartify).toList();
19+
}
20+
1621
var json = js.stringify(jsObject);
1722
return JSON.decode(json);
1823
}
@@ -23,13 +28,7 @@ dynamic jsify(Object dartObject) {
2328
return dartObject;
2429
}
2530

26-
Object json;
27-
try {
28-
json = JSON.encode(dartObject, toEncodable: _noCustomEncodable);
29-
} on JsonUnsupportedObjectError {
30-
throw new ArgumentError("Only basic JS types are supported");
31-
}
32-
return js.parse(json);
31+
return util.jsify(dartObject);
3332
}
3433

3534
/// Returns [:true:] if the [value] is a very basic built-in type - e.g.
@@ -41,9 +40,6 @@ bool _isBasicType(value) {
4140
return false;
4241
}
4342

44-
_noCustomEncodable(value) =>
45-
throw new UnsupportedError("Object with toJson shouldn't work either");
46-
4743
/// Handles the [thenable] object.
4844
Future<T> handleThenable<T>(ThenableJsImpl<T> thenable) {
4945
var completer = new Completer<T>();

0 commit comments

Comments
 (0)