Type Alias: LixHooks

LixHooks = object

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, data?) => 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

eventType

string

data?

any

Returns

void


onFileChange()

onFileChange: (handler) => () => void

Listen to file change events.

Note: This API will become redundant once subscriptions are implemented.

Fires when a file is inserted, updated, or deleted in the database. Useful for updating UI, triggering re-parsing, or synchronizing external systems.

Parameters

handler

(fileId, operation) => void

Function to call when a file changes

Returns

Unsubscribe function to remove the listener

(): void

Returns

void

Example

const unsubscribe = lix.hooks.onFileChange((fileId, operation) => {
  console.log(`File ${fileId} was ${operation}`);
  if (operation === 'updated') {
    reloadEditor(fileId);
  }
});

// Later, remove the listener
unsubscribe();

onStateCommit()

onStateCommit: (handler) => () => 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.

Parameters

handler

(data) => void

Function to call when state is committed

Returns

Unsubscribe function to remove the listener

(): void

Returns

void

Example

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

// Later, remove the listener
unsubscribe();