5inful1
02/27/2022, 3:00 PMjs
//pointsStore.js
import { supabase } from './supabase.js';
import { writable, get } from 'svelte/store';
export const pts = writable(false, (set) => {
supabase
.from('points')
.select('*')
.then(({data}) => set(data))
const mySubscription = supabase
.from('points')
.on('INSERT', (payload) => set([...get(pts), payload.new]))
.subscribe();
return () => supabase.removeSubscription(mySubscription);
});
Ok I'm trying this way instead however I still don't know if this will generate errors.garyaustin
02/27/2022, 3:18 PMconst mySubscription = supabase
.from('table')
.on('*', payload => {
console.log('update',payload)
})
.subscribe((status) => {
console.log('status', status)
if (status === "SUBSCRIBED") {
supabase
.from('table')
.select('*')
.then(response => {
console.log('init data',response.data)
})
}
})
My real code flow is more complex as I also deal with resetting table data when subscription errors occur.5inful1
02/27/2022, 9:17 PM