Skip to content

Event/hook system for record changes #3

@cuibonobo

Description

@cuibonobo

There is currently no way to react to record lifecycle events. Apps can't observe when records are created, updated, or deleted without polling.

This matters for several use cases:

  • Full-text or secondary indexing — rebuild an index when a record changes
  • Sync — propagate local writes to a remote when the adapter-api lands
  • Audit logging — record who changed what and when
  • Reactive UI — invalidate caches or trigger re-renders on write

Proposed API (sketch):

stack.on('record:create', (record) => { ... });
stack.on('record:update', (record, previous) => { ... });
stack.on('record:delete', (id, { hard }) => { ... });
// or filtered by type:
stack.on('record:update', { typeId: 'com.example.app/note@1' }, (record) => { ... });

Hooks could be synchronous (fire-and-forget) or async (awaited before the write completes — useful for indexing). The right model needs thought, especially around error handling if a hook throws.

The adapter interface may also need a hook mechanism so that adapters (particularly adapter-api) can emit events from remote changes, not just local writes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions