Type Alias: LixHooks

LixHooks = { _emit: (eventType: string, data?: any) => void; onStateCommit: (handler: (data: { changes: StateCommitChange[]; }) => void) => () => void; }

Lix hooks system for listening to database lifecycle events.

Hooks allow you to register callbacks that fire at specific points in Lix's execution, such as when state changes are committed.

Properties

_emit()

_emit: (eventType: string, data?: any) => 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.

Parameters

ParameterType
eventTypestring
data?any

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.

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