-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!(realtime_client): Introduce type safe realtime methods #725
Conversation
I think I really like the new design! I haven't worked much with presence or broadcast, but it was always strange to have all arguments for all realtime functionalities in one method. It's easier to read as well. |
Sounds great! I will finish up this PR! |
I have updated the final channel = supabase.channel('name');
channel
.onPostgresChanges(
event: PostgresChangeEvent.all,
schema: 'public',
table: 'my_table',
filter: PostgresChangeFilter(
type: PostgresChangeFilterType.eq,
column: 'id',
value: 1,
),
callback: (PostgresChangePayload payload) {
// `PostgresChangePayload` is a new class dedicated for this payload
final Map<String, dynamic> newRecord = payload
.newRecord; // Wanted to use `new`, but `new` is a reserved keyword in Dart, so couldn't use it.
final Map<String, dynamic> oldRecord = payload.oldRecord;
})
.onBroadcast(
event: 'broadcast_event',
callback: (Map<String, dynamic> payload) {
print(payload);
})
.onPresence(
event: PresenceEvent.join,
callback: (Map<String, dynamic> payload) {
print(payload);
})
.subscribe(); |
Also, currently we use the await myChannel.sendBroadcastMessage(
event: 'cursor-pos',
payload: {'x': 30, 'y': 50},
); |
What kind of change does this PR introduce?
Currently, the realtime methods are not type safe. This is due to how
channel.on()
method has to be able to support postgres changes, broadcast, and presence.The proposal is to introduce three different methods
onPostgresChanges
,onBroadcast
, andonPresence
that will each handle their respective realtime features. That way, we would be able to restrict what parameters to accept or the type of the payload.The public API would look something like this:
Open to hearing any opinions about it. I'm sure the proposed public API isn't the best design either, so would love to hear anything regarding it as well.