Skip to content

Commit 6773d6e

Browse files
committed
feat: reduce Realtime footprint to four helper methods
1 parent 18d7a90 commit 6773d6e

File tree

9 files changed

+114
-271
lines changed

9 files changed

+114
-271
lines changed

example/next-storage/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ create policy "Users can update own profile."
3737
-- Set up Realtime!
3838
begin;
3939
drop publication if exists supabase_realtime;
40-
create publication supabase_realtime;
40+
create publication supabase_realtime for table profiles;
4141
commit;
42-
alter publication supabase_realtime add table profiles;
4342

4443
-- Set up Storage!
4544
insert into storage.buckets (id, name)

example/next-storage/components/ProfileList.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ProfileCard from '../components/ProfileCard'
22
import { Profile } from '../lib/constants'
3-
import { SupabaseRealtimePayload } from '@supabase/supabase-js'
43
import { supabase } from '../lib/api'
54
import { useState, useEffect } from 'react'
65

@@ -14,9 +13,9 @@ export default function ProfileList() {
1413
const realtimeProfiles = supabase
1514
.channel('profiles-channel')
1615
.on(
17-
'realtime',
16+
'postgres_changes',
1817
{ event: '*', schema: 'public', table: 'profiles' },
19-
(payload: SupabaseRealtimePayload<Profile>) => profileUpdated(profiles, payload.new)
18+
(payload: { [key: string]: any }) => profileUpdated(profiles, payload.new)
2019
)
2120
.subscribe()
2221

example/next-todo/components/TodoList.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ export default function Todos({ user }) {
1414

1515
subscription1 = supabase
1616
.channel('todos-table-channel')
17-
.on('realtime', { event: 'UPDATE', schema: 'public', table: 'todos' }, (v) =>
17+
.on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'todos' }, (v) =>
1818
console.log('UPDATE on todos', v)
1919
)
20-
.on('realtime', { event: 'INSERT', schema: 'public', table: 'todos' }, (v) =>
20+
.on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'todos' }, (v) =>
2121
console.log('INSERT on todos', v)
2222
)
2323
.subscribe((change) => console.log('todos changed', change))
2424

2525
subscription2 = supabase
2626
.channel('public-schema-channel')
27-
.on('realtime', { event: 'UPDATE', schema: 'public' }, (v) =>
27+
.on('postgres_changes', { event: 'UPDATE', schema: 'public' }, (v) =>
2828
console.log('UPDATE on schema', v)
2929
)
30-
.on('realtime', { event: 'INSERT', schema: 'public' }, (v) =>
30+
.on('postgres_changes', { event: 'INSERT', schema: 'public' }, (v) =>
3131
console.log('INSERT on schema', v)
3232
)
3333
.subscribe((change) => console.log('schema changed', change))

package-lock.json

Lines changed: 81 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@supabase/functions-js": "^1.4.0-next.1",
4141
"@supabase/gotrue-js": "^1.23.0-next.15",
4242
"@supabase/postgrest-js": "^1.0.0-next.6",
43-
"@supabase/realtime-js": "^1.8.0-next.13",
43+
"@supabase/realtime-js": "^1.8.0-next.15",
4444
"@supabase/storage-js": "^1.8.0-next.5",
4545
"cross-fetch": "^3.1.5"
4646
},

0 commit comments

Comments
 (0)