```js //pointsStore.js import { supabase } from '....
# help
u
Copy code
js
//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.
g
Not directly commenting on your unsubscribe issue but in general what you are showing is how mySubscription is used. BUT if you are doing a real project where multiple users can insert data into the table, then you probably want your table select done after you have subscription set up. If you don't, you could lose data inserts while the subscription is being set up. It is a small window, but could be a second or more. I do something like this:
Copy code
const 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.
u
thankyou😀 this is very interesting!!