API Reference
withMemoryListeners
function withMemoryListeners(memory, listener): Memory;Defined in: compose.ts:160
Wrap a Memory so a MemoryListener is notified after each operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
memory | Memory | The memory backend to wrap. |
listener | MemoryListener | Callbacks invoked after each successful operation. |
Returns
A Memory that notifies listener after each op.
Remarks
This is the observer/listener seam for storage — the counterpart to withModelObserver for the model. Listeners only react (logging, metrics, cache warming); each callback runs after the underlying op succeeds and its return value is ignored, so the result the loop sees is never altered.
Attach more than one listener by wrapping more than once — wrappers stack.
Example
const logged = withMemoryListeners(store, {
onAppend: (id, messages) => console.log(`+${messages.length} to ${id}`),
});