Skip to content

Feature request: Change source/origin tracking in onChange #632

@AleksY1991

Description

@AleksY1991

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);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions