Skip to content

Commit 5b46ea3

Browse files
Merge branch 'FME-11223-web-support-polishing' into FME-11223-web-support-js-interop-improvements
2 parents ecd1a8d + a6fcbad commit 5b46ea3

File tree

4 files changed

+20
-38
lines changed

4 files changed

+20
-38
lines changed

splitio_web/lib/splitio_web.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class SplitioWeb extends SplitioPlatform {
9292
// Create and inject script tag
9393
final script = document.createElement('script') as HTMLScriptElement;
9494
script.type = 'text/javascript';
95-
script.src = 'packages/splitio_web/web/split-browser-1.6.0.full.min.js';
95+
script.src = 'assets/packages/splitio_web/web/split-browser-1.6.0.full.min.js';
9696

9797
// Wait for script to load
9898
final completer = Completer<void>();

splitio_web/lib/src/js_interop.dart

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -236,40 +236,21 @@ extension type JS_BrowserSDKPackage._(JSObject _) implements JSObject {
236236
external JSArray<JSString> objectKeys(JSObject obj);
237237

238238
@JS('Reflect.get')
239-
external JSAny? reflectGet(JSObject target, JSAny propertyKey);
239+
external JSAny? reflectGet(JSObject target, JSString propertyKey);
240240

241241
@JS('Reflect.set')
242-
external JSAny? reflectSet(JSObject target, JSAny propertyKey, JSAny? value);
242+
external JSAny? reflectSet(JSObject target, JSString propertyKey, JSAny? value);
243243

244244
@JS('JSON.parse')
245245
external JSObject jsonParse(JSString obj);
246246

247-
List<dynamic> jsArrayToList(JSArray obj) {
248-
return obj.toDart.map(jsAnyToDart).toList();
249-
}
250-
251-
Map<String, dynamic> jsObjectToMap(JSObject obj) {
252-
return {
253-
for (final jsKey in objectKeys(obj).toDart)
254-
jsKey.toDart: jsAnyToDart(reflectGet(obj, jsKey)),
255-
};
256-
}
257-
258-
dynamic jsAnyToDart(JSAny? value) {
259-
if (value is JSArray) {
260-
return jsArrayToList(value);
261-
} else if (value is JSObject) {
262-
return jsObjectToMap(value);
263-
} else if (value is JSString) {
264-
return value.toDart;
265-
} else if (value is JSNumber) {
266-
return value.toDartDouble;
267-
} else if (value is JSBoolean) {
268-
return value.toDart;
269-
} else {
270-
return value; // JS null and undefined are null in Dart
271-
}
272-
}
247+
List<dynamic> jsArrayToList(JSArray<JSAny?> obj) =>
248+
(obj.dartify() as List).cast<dynamic>();
249+
250+
Map<String, dynamic> jsObjectToMap(JSObject obj) =>
251+
(obj.dartify() as Map).cast<String, dynamic>();
252+
253+
Object? jsAnyToDart(JSAny? value) => value.dartify();
273254

274255
// Conversion utils: JS SDK to Flutter SDK types
275256

@@ -283,8 +264,7 @@ Map<String, SplitResult> jsTreatmentsWithConfigToMap(JSObject obj) {
283264
}
284265

285266
SplitResult jsTreatmentWithConfigToSplitResult(JS_TreatmentWithConfig obj) {
286-
return SplitResult(obj.treatment.toDart,
287-
(obj.config is JSString) ? obj.config!.toDart : null);
267+
return SplitResult(obj.treatment.toDart, obj.config?.toDart);
288268
}
289269

290270
Prerequisite jsPrerequisiteToPrerequisite(JS_Prerequisite obj) {

splitio_web/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ repository: https://github.com/splitio/flutter-sdk-plugin/tree/main/splitio_web
44
version: 1.0.0
55

66
environment:
7-
sdk: ">=3.3.0 <4.0.0"
8-
flutter: ">=3.16.0"
7+
sdk: ">=3.3.0 <4.0.0" # using Dart 3.3+ extension types for JS interop
8+
flutter: ">=3.19.0" # lowest Flutter version that includes Dart 3.3+
99

1010
flutter:
1111
plugin:

splitio_web/test/splitio_web_test.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import 'package:flutter_test/flutter_test.dart';
55
import 'package:splitio_web/splitio_web.dart';
66
import 'package:splitio_web/src/js_interop.dart';
77
import 'package:splitio_platform_interface/split_certificate_pinning_configuration.dart';
8-
import 'package:splitio_platform_interface/split_configuration.dart';
9-
import 'package:splitio_platform_interface/split_evaluation_options.dart';
108
import 'package:splitio_platform_interface/split_sync_config.dart';
11-
import 'package:splitio_platform_interface/split_result.dart';
129
import 'package:splitio_platform_interface/split_rollout_cache_configuration.dart';
1310
import 'utils/js_interop_test_utils.dart';
1411

@@ -722,8 +719,10 @@ void main() {
722719
)));
723720

724721
expect(mock.calls[mock.calls.length - 5].methodName, 'SplitFactory');
722+
final actual =
723+
jsAnyToDart(mock.calls[mock.calls.length - 5].methodArguments[0]);
725724
expect(
726-
jsAnyToDart(mock.calls[mock.calls.length - 5].methodArguments[0]),
725+
actual,
727726
equals({
728727
'core': {
729728
'authorizationKey': 'api-key',
@@ -773,7 +772,10 @@ void main() {
773772
'expirationDays': 100,
774773
'clearOnInit': true
775774
},
776-
'impressionListener': {'logImpression': {}}
775+
'impressionListener': {
776+
'logImpression': (actual as Map)['impressionListener']
777+
['logImpression']
778+
}
777779
}));
778780

779781
expect(mock.calls[mock.calls.length - 4].methodName, 'warn');

0 commit comments

Comments
 (0)