Skip to content

Commit 7e8cea2

Browse files
committed
convert before validation event to extension type
1 parent a01f81c commit 7e8cea2

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
1-
import 'package:js/js.dart';
2-
import 'package:js/js_util.dart';
1+
import 'dart:js_interop';
32

43
import '../../../models/screenset_event.dart';
54
import '../models/profile.dart';
65

7-
/// This typedef defines the function signature for the handler of the screenset before validation event.
8-
///
9-
/// This function should return a [Future] that resolves with a [Map] containing the error messages per field in the form.
10-
/// If there are no errors, this future should resolve with `null` as value.
11-
typedef BeforeValidationEventHandler = Future<Map<String, dynamic>?> Function(ScreensetEvent event);
12-
13-
/// The static interop class for the before validation event of the `Account.showScreenset` event stream.
6+
/// The extension type for the before validation event of the `Account.showScreenset` event stream.
147
///
158
/// See: https://help.sap.com/docs/SAP_CUSTOMER_DATA_CLOUD/8b8d6fffe113457094a17701f63e3d6a/413a5b7170b21014bbc5a10ce4041860.html?locale=en-US#onbeforevalidation
169
@JS()
1710
@anonymous
1811
@staticInterop
19-
class BeforeValidationEvent {}
20-
21-
/// This extension defines the static interop definition
22-
/// for the [BeforeValidationEvent] class.
23-
extension BeforeValidationEventExtension on BeforeValidationEvent {
24-
/// The data object for the user. This will be empty if the user is not logged in.
25-
external Object? get data;
12+
extension type BeforeValidationEvent(JSObject _) {
13+
/// The data object for the user.
14+
/// This will be empty if the user is not logged in.
15+
external JSAny? get data;
2616

2717
/// The name of the event.
2818
external String get eventName;
@@ -31,7 +21,7 @@ extension BeforeValidationEventExtension on BeforeValidationEvent {
3121
external String get form;
3222

3323
/// An object containing the properties of the form fields.
34-
external Object? get formData;
24+
external JSAny? get formData;
3525

3626
/// The profile object for the user. This will be empty if the user is not logged in.
3727
external Profile? get profile;
@@ -44,22 +34,25 @@ extension BeforeValidationEventExtension on BeforeValidationEvent {
4434
/// e.g., 'showLoginUI', 'showCommentsUI', etc.
4535
external String get source;
4636

47-
/// The subscriptions data for the user. This will be empty if the user is not logged in.
48-
external Object? get subscriptions;
37+
// TODO: This should be the subscriptions static interop type.
38+
39+
/// The subscriptions data for the user.
40+
/// This will be empty if the user is not logged in.
41+
external JSAny? get subscriptions;
4942

5043
/// Serialize this event into a [ScreensetEvent].
5144
ScreensetEvent serialize() {
5245
return ScreensetEvent(
5346
eventName,
5447
<String, dynamic>{
55-
'data': dartify(data),
48+
'data': data.dartify(),
5649
'form': form,
57-
'formData': dartify(formData),
50+
'formData': formData.dartify(),
5851
'profile': profile?.toMap(),
5952
'screen': screen,
6053
'source': source,
61-
'subscriptions': dartify(subscriptions),
54+
'subscriptions': subscriptions.dartify(),
6255
},
6356
);
6457
}
65-
}
58+
}

0 commit comments

Comments
 (0)