Skip to content

Commit a4b0de2

Browse files
committed
chore: review
1 parent d6611d5 commit a4b0de2

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

templates/android/library/src/main/java/io/package/models/RealtimeModels.kt.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ data class RealtimeCallback(
1717

1818
open class RealtimeResponse(
1919
val type: String,
20-
val data: Any
20+
val data: Any? = null
2121
)
2222

2323
data class RealtimeResponseEvent<T>(

templates/flutter/lib/src/realtime_response.dart.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RealtimeResponse {
3030
factory RealtimeResponse.fromMap(Map<String, dynamic> map) {
3131
return RealtimeResponse(
3232
type: map['type'] ?? '',
33-
data: (map.containsKey('data')) ? Map<String, dynamic>.from(map['data']) : {},
33+
data: Map<String, dynamic>.from(map['data'] ?? {}),
3434
);
3535
}
3636

templates/react-native/src/client.ts.twig

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Headers = {
1212

1313
type RealtimeResponse = {
1414
type: 'error' | 'event' | 'connected' | 'response' | 'pong';
15-
data: RealtimeResponseAuthenticated | RealtimeResponseConnected | RealtimeResponseError | RealtimeResponseEvent<unknown>;
15+
data: RealtimeResponseAuthenticated | RealtimeResponseConnected | RealtimeResponseError | RealtimeResponseEvent<unknown> | undefined;
1616
}
1717

1818
type RealtimeRequest = {
@@ -291,16 +291,18 @@ class Client {
291291
switch (message.type) {
292292
case 'event':
293293
if(!message.data) return;
294-
let data = <RealtimeResponseEvent<unknown>>message.data;
295-
if (data?.channels) {
296-
const isSubscribed = data.channels.some(channel => this.realtime.channels.has(channel));
297-
if (!isSubscribed) return;
298-
this.realtime.subscriptions.forEach(subscription => {
299-
if (data.channels.some(channel => subscription.channels.includes(channel))) {
300-
setTimeout(() => subscription.callback(data));
301-
}
302-
})
303-
}
294+
295+
const data = message.data as RealtimeResponseEvent<unknown>;
296+
if (!data?.channels) return;
297+
298+
const isSubscribed = data.channels.some(channel => this.realtime.channels.has(channel));
299+
if (!isSubscribed) return;
300+
301+
this.realtime.subscriptions.forEach(subscription => {
302+
if (data.channels.some(channel => subscription.channels.includes(channel))) {
303+
setTimeout(() => subscription.callback(data));
304+
}
305+
});
304306
break;
305307
case 'pong':
306308
break; // Handle pong response if needed

templates/web/src/client.ts.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ type Headers = {
1919
*/
2020
type RealtimeResponse = {
2121
/**
22-
* Type of the response: 'error', 'event', 'connected', 'pong', or 'response'.
22+
* Type of the response: 'error', 'event', 'connected', 'response' or 'pong'.
2323
*/
2424
type: 'error' | 'event' | 'connected' | 'response' | 'pong';
2525

2626
/**
2727
* Data associated with the response based on the response type.
2828
*/
29-
data: RealtimeResponseAuthenticated | RealtimeResponseConnected | RealtimeResponseError | RealtimeResponseEvent<unknown>;
29+
data: RealtimeResponseAuthenticated | RealtimeResponseConnected | RealtimeResponseError | RealtimeResponseEvent<unknown> | undefined;
3030
}
3131

3232
/**

0 commit comments

Comments
 (0)