SnapshotObserver


An observer for the snapshot system that notifies an observer when a snapshot is created, applied, and/or disposed.

All methods are called in the thread of the snapshot so all observers must be thread safe as they may be called from any thread.

Calling any of the Snapshot API (including, reading or writing mutable state objects) is not supported and may produce inconsistent result or throw an exception.

Summary

Public functions

open Unit
onApplied(snapshot: Snapshot, changed: Set<Any>)

Called after a snapshot is applied.

Cmn
open Unit
onCreated(
    snapshot: Snapshot,
    parent: Snapshot?,
    observers: SnapshotInstanceObservers?
)

Called after snapshot is created.

Cmn
open SnapshotInstanceObservers?
onCreating(parent: Snapshot?, readonly: Boolean)

Called before a snapshot is created allowing reads and writes to the snapshot to be observed.

Cmn
open Unit
onDisposing(snapshot: Snapshot)

Called while a snapshot is being disposed.

Cmn

Public functions

onApplied

open fun onApplied(snapshot: Snapshot, changed: Set<Any>): Unit

Called after a snapshot is applied.

For nested snapshots, the changes will only be visible to the parent snapshot, not globally. Snapshots do not have a parent will have changes that are visible globally and such notification are equivalent the notification sent to Snapshot.registerApplyObserver and will include all objects modified by any nested snapshots that have been applied to the parent snapshot.

This method is called in the same thread that applies the snapshot.

Parameters
snapshot: Snapshot

the snapshot that was applied.

changed: Set<Any>

the set of objects that were modified during the snapshot.

onCreated

open fun onCreated(
    snapshot: Snapshot,
    parent: Snapshot?,
    observers: SnapshotInstanceObservers?
): Unit

Called after snapshot is created.

This is called prior to the instance being returned by Snapshot.takeSnapshot or Snapshot.takeMutableSnapshot.

This method is called in the same thread that creates the snapshot.

Parameters
snapshot: Snapshot

the snapshot that was created.

parent: Snapshot?

the parent snapshot for the new snapshot if it is a nested snapshot or null if it is a root snapshot.

observers: SnapshotInstanceObservers?

the read and write observers that were installed by the value returned by onCreated. This allows correlating which snapshot observers returned by onCreating to the snapshot that was created.

onCreating

open fun onCreating(parent: Snapshot?, readonly: Boolean): SnapshotInstanceObservers?

Called before a snapshot is created allowing reads and writes to the snapshot to be observed.

This method is called in the same thread that creates the snapshot.

Parameters
parent: Snapshot?

the parent snapshot for the new snapshot if it is a nested snapshot or null otherwise.

readonly: Boolean

whether the snapshot being created will be read-only.

Returns
SnapshotInstanceObservers?

optional read and write observers that will be added to the snapshot created.

onDisposing

open fun onDisposing(snapshot: Snapshot): Unit

Called while a snapshot is being disposed.

This method is called in the same thread that disposes the snapshot.

Parameters
snapshot: Snapshot

information about the snapshot that was created.