Skip to content

@statesync/electron


@statesync/electron / createElectronSnapshotProvider

Function: createElectronSnapshotProvider() ​

ts
function createElectronSnapshotProvider<T>(options): SnapshotProvider<T>;

Defined in: transport.ts:125

Creates a SnapshotProvider that fetches snapshots from the main process via Electron IPC invoke.

When SnapshotProvider.getSnapshot is called, it sends an ipcRenderer.invoke() request to the main process on the configured channel and returns the resulting SnapshotEnvelope.

Mirrors createTauriSnapshotProvider in the @statesync/tauri package.

Process context: renderer process.

Type Parameters ​

Type ParameterDescription
TThe application-specific snapshot data type.

Parameters ​

ParameterTypeDescription
optionsElectronSnapshotProviderOptionsConfiguration specifying the invoke function and IPC channel.

Returns ​

SnapshotProvider<T>

A SnapshotProvider compatible with the core engine's RevisionSyncOptions.provider option.

Example ​

ts
const provider = createElectronSnapshotProvider<TodoList>({
  invoke: bridge.invoke,
  channel: 'statesync:todos:snapshot',
});

const envelope = await provider.getSnapshot();
console.log(envelope.revision, envelope.data);

Released under the MIT License.