StateFieldBuilder

Builder scope for defining a StateField via DSL.

Example:

val counter = StateField.define<Int> {
create { 0 }
update { value, tr -> value + tr.changes.newLength }
}

Functions

Link copied to clipboard
fun compare(block: (Value, Value) -> Boolean)

Set a custom comparison function (defaults to ==).

Link copied to clipboard
fun create(block: (EditorState) -> Value)

Set the function that creates the initial value for this field.

Link copied to clipboard
fun provide(block: (StateField<Value>) -> Extension)

Provide an extension derived from this field (e.g. a facet provider).

Link copied to clipboard
fun serialization(serializer: KSerializer<Value>)

Set type-safe serialization using a kotlinx.serialization.KSerializer.

fun serialization(toJSON: (Value, EditorState) -> Any?, fromJSON: (Any?, EditorState) -> Value)

Set custom JSON serialization for this field.

Link copied to clipboard
fun update(block: (Value, Transaction) -> Value)

Set the function that updates the value on each transaction.