Skip to content

Commit ef30e67

Browse files
Merge branch 'FME-11223-web-support-unsupported-configs' into FME-11223-web-support-client-evaluation
2 parents 029e9f1 + ab03300 commit ef30e67

File tree

3 files changed

+38
-35
lines changed

3 files changed

+38
-35
lines changed

splitio_web/lib/src/js_interop.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'dart:js_interop';
22

3+
// JS SDK types
4+
35
@JS()
46
extension type JS_Logger._(JSObject _) implements JSObject {
57
external JSFunction warn;
@@ -30,3 +32,39 @@ extension type JS_BrowserSDKPackage._(JSObject _) implements JSObject {
3032
external JSFunction? WarnLogger;
3133
external JSFunction? ErrorLogger;
3234
}
35+
36+
// Conversion utils: JS to Dart types
37+
38+
@JS('Object.keys')
39+
external JSArray<JSString> _objectKeys(JSObject obj);
40+
41+
@JS('Reflect.get')
42+
external JSAny? _reflectGet(JSObject target, JSAny propertyKey);
43+
44+
List<dynamic> jsArrayToList(JSArray obj) {
45+
return obj.toDart.map(jsAnyToDart).toList();
46+
}
47+
48+
Map<String, dynamic> jsObjectToMap(JSObject obj) {
49+
return {
50+
for (final jsKey in _objectKeys(obj).toDart)
51+
// @TODO _reflectGet (js_interop) vs obj.getProperty (js_interop_unsafe)
52+
jsKey.toDart: jsAnyToDart(_reflectGet(obj, jsKey)),
53+
};
54+
}
55+
56+
dynamic jsAnyToDart(JSAny? value) {
57+
if (value is JSArray) {
58+
return jsArrayToList(value);
59+
} else if (value is JSObject) {
60+
return jsObjectToMap(value);
61+
} else if (value is JSString) {
62+
return value.toDart;
63+
} else if (value is JSNumber) {
64+
return value.toDartDouble;
65+
} else if (value is JSBoolean) {
66+
return value.toDart;
67+
} else {
68+
return value; // JS null and undefined are null in Dart
69+
}
70+
}

splitio_web/test/splitio_web_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:splitio_platform_interface/split_configuration.dart';
99
import 'package:splitio_platform_interface/split_evaluation_options.dart';
1010
import 'package:splitio_platform_interface/split_sync_config.dart';
1111
import 'package:splitio_platform_interface/split_rollout_cache_configuration.dart';
12-
import 'utils/js_interop_test_utils.dart';
1312

1413
extension on web.Window {
1514
@JS()

splitio_web/test/utils/js_interop_test_utils.dart

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)