Type Alias: LixHooks

LixHooks = { _emit: <T>(eventType: T, data: HookEvents[T]) => void; onStateCommit: (handler: (data: { changes: StateCommitChange[]; }) => void) => () => void; }

Properties

_emit()

_emit: <T>(eventType: T, data: HookEvents[T]) => void

Internal

Internal method for emitting events.

This method is for internal use only and should not be called directly. Use this to emit events from state mutation functions.

Type Parameters

Type Parameter
T extends HookEventType

Parameters

ParameterType
eventTypeT
dataHookEvents[T]

Returns

void


onStateCommit()

onStateCommit: (handler: (data: { changes: StateCommitChange[]; }) => void) => () => void

Listen to state commit events.

Fires after any state mutation is committed to the database. Useful for auto-saving, cache invalidation, sync operations, etc.

Payload carries changes: StateCommitChange[], including writer_key for each state row (when applicable). For UIs, filter by writer to suppress echoes, e.g.:

const writer_key = 'app_component_<session_id>'
lix.hooks.onStateCommit(({ changes }) => {
  const external = changes.some(c =>
    c.file_id === activeFileId && (c.writer_key == null || c.writer_key !== writer_key)
  )
  if (external) refresh()
})

Example

const unsubscribe = lix.hooks.onStateCommit(() => {
  console.log('State was committed!');
  storage.save();
});

// Later, remove the listener
unsubscribe();

Parameters

ParameterTypeDescription
handler(data: { changes: StateCommitChange[]; }) => voidFunction to call when state is committed

Returns

Unsubscribe function to remove the listener

(): void

Returns

void