Document

class Document(val key: Document.Key, options: Document.Options = Options(), dispatcher: CoroutineDispatcher = createSingleThreadDispatcher("Document($key)")) : 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.

Constructors

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

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
Link copied to clipboard
suspend fun getValueByPath(path: String): JsonElement?

Returns the JsonElement corresponding to the path.

Link copied to clipboard
fun toJson(): String
Link copied to clipboard
fun updateAsync(message: String? = null, updater: suspend (root: JsonObject, presence: Presence) -> Unit): Deferred<Boolean>

Executes the given updater to update this document.