Use case:
Building custom sync logic with Supabase Realtime. Need to distinguish:
- User changes → sync to database
- Realtime changes → update local state, skip re-sync to avoid loops
Current workaround:
Module-scoped flags checked in onChange:
let isRemote = false;
store$.nodes.onChange(({ changes }) => {
if (isRemote) return; // skip sync
syncToDatabase(changes);
});
// Realtime handler:
isRemote = true;
store$.nodes[id].set(data);
isRemote = false;
Problems:
- Flags are module-scoped, not composable
- Any code can write to observables without setting flags
- No enforcement, purely convention-based
Proposed solution:
Optional source or context parameter on writes that flows through to onChange:
store$.nodes[id].set(data, { source: 'remote' });
store$.nodes.onChange(({ changes, source }) => {
if (source === 'remote') return;
syncToDatabase(changes);
});
Use case:
Building custom sync logic with Supabase Realtime. Need to distinguish:
Current workaround:
Module-scoped flags checked in onChange:
let isRemote = false;
store$.nodes.onChange(({ changes }) => {
if (isRemote) return; // skip sync
syncToDatabase(changes);
});
// Realtime handler:
isRemote = true;
store$.nodes[id].set(data);
isRemote = false;
Problems:
Proposed solution:
Optional source or context parameter on writes that flows through to onChange:
store$.nodes[id].set(data, { source: 'remote' });
store$.nodes.onChange(({ changes, source }) => {
if (source === 'remote') return;
syncToDatabase(changes);
});