Document

class Document(val key: Document.Key, options: Document.Options = Options(), dispatcher: CoroutineDispatcher = createSingleThreadDispatcher("Document($key)"), snapshotDispatcher: CoroutineDispatcher = dispatcher) : Closeable

A CRDT-based data type. We can represent the model of the application and edit it even while offline.

A single-threaded, Closeable is used as default. Therefore you need to close the document, when the document is no longer needed. If you provide your own dispatcher, it is up to you to decide close is needed or not. snapshotDispatcher can be set differently from dispatcher, as snapshot operation can be much heavier than other operations.

Constructors

Link copied to clipboard
constructor(key: Document.Key, options: Document.Options = Options(), dispatcher: CoroutineDispatcher = createSingleThreadDispatcher("Document($key)"), snapshotDispatcher: CoroutineDispatcher = dispatcher)

Types

Link copied to clipboard

Represents the status of the Document.

Link copied to clipboard
interface Event
Link copied to clipboard
value class Key(val value: String)

Represents a unique key to identify Document.

Link copied to clipboard
data class Options(val disableGC: Boolean = false)

Properties

Link copied to clipboard
val events: SharedFlow<Document.Event>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val presences: StateFlow<Presences>
Link copied to clipboard

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
fun events(targetPath: String): Flow<Document.Event>

Subscribes to events on the document with the specific targetPath.

Link copied to clipboard

Deletes elements that were removed before the given time.

Link copied to clipboard
suspend fun getRoot(): JsonObject

Returns a new proxy of cloned root.

Link copied to clipboard

Returns a new proxy of deep-copied root. It ensures thread-safety by avoiding reuse of clone.

Link copied to clipboard
suspend fun getValueByPath(path: String): JsonElement?

Returns the JsonElement corresponding to the path.

Link copied to clipboard
suspend fun publishEvent(event: Document.Event)
Link copied to clipboard
fun toJson(): String
Link copied to clipboard
fun updateAsync(message: String? = null, updater: suspend (root: JsonObject, presence: Presence) -> Unit): Deferred<OperationResult>

Executes the given updater to update this document.