Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions splitio_web/lib/splitio_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,32 +349,32 @@ class SplitioWeb extends SplitioPlatform {
return _clients[key]!;
}

JSAny? _convertValue(dynamic value, bool isAttributes) {
JSAny? _convertValue(dynamic value, bool isAttribute) {
if (value is bool) return value.toJS;
if (value is num) return value.toJS; // covers int + double
if (value is String) return value.toJS;

// properties do not support lists and sets
if (isAttributes) {
if (isAttribute) {
if (value is List) return value.jsify();
if (value is Set) return value.jsify();
}

return null;
}

JSObject _convertMap(Map<String, dynamic> dartMap, bool isAttributes) {
JSObject _convertMap(Map<String, dynamic> dartMap, bool isAttribute) {
final jsMap = JSObject();

dartMap.forEach((key, value) {
final jsValue = _convertValue(value, isAttributes);
final jsValue = _convertValue(value, isAttribute);

if (jsValue != null) {
jsMap.setProperty(key.toJS, jsValue);
} else {
this._factory.settings.log.warn.callAsFunction(
null,
'Invalid ${isAttributes ? 'attribute' : 'property'} value: $value, for key: $key, will be ignored'
'Invalid ${isAttribute ? 'attribute' : 'property'} value: $value, for key: $key, will be ignored'
.toJS);
}
});
Expand Down Expand Up @@ -569,4 +569,31 @@ class SplitioWeb extends SplitioPlatform {

return jsTreatmentsWithConfigToMap(result);
}

@override
Future<bool> track(
{required String matchingKey,
required String? bucketingKey,
required String eventType,
String? trafficType,
double? value,
Map<String, dynamic> properties = const {}}) async {
final client = await _getClient(
matchingKey: matchingKey,
bucketingKey: bucketingKey,
);

final result = client.track.callAsFunction(
null,
trafficType != null
? trafficType.toJS
: this._trafficType != null
? this._trafficType!.toJS
: null,
eventType.toJS,
value != null ? value.toJS : null,
_convertMap(properties, false)) as JSBoolean;

return result.toDart;
}
}
1 change: 1 addition & 0 deletions splitio_web/lib/src/js_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extension type JS_IBrowserClient._(JSObject _) implements JSObject {
external JSFunction getTreatmentsByFlagSets;
external JSFunction getTreatmentsWithConfigByFlagSet;
external JSFunction getTreatmentsWithConfigByFlagSets;
external JSFunction track;
}

@JS()
Expand Down
Loading