Skip to content

v5.3.0

Compare
Choose a tag to compare
@cinnamon-bun cinnamon-bun released this 04 Oct 20:09

More detailed change events

df853ef

IStorage instances now emit more detailed change events when a document is written (modified, created, deleted).

IStorage.onWrite is a newly added Emitter which sends out objects like this:

export type WriteEvent = {
    kind: 'DOCUMENT_WRITE',
    // a write is "local" if it comes from IStorage.set()
    // otherwise it's "remote" (it came from a sync).
    isLocal: boolean,
    document: Document,
}

Use it like this:

myStorage.onWrite((event: WriteEvent) => {
    console.log(`a document changed at ${document.path}`);
});

Deprecations

The previous Emitter, IStorage.onChange, still exists and is triggered in the same situations, but it does not send any info to callbacks. It's deprecated and will be removed eventually.