UndoRedo

class UndoRedo(maxQueueSize: Int)

An object that allows to undo and redo any actions happening in the pro.respawn.flowmvi.api.Store. Keep a reference to the object instance to call undo, redo, and invoke. Don't forget to install the corresponding plugin with undoRedoPlugin.

Constructors

Link copied to clipboard
constructor(maxQueueSize: Int)

Types

Link copied to clipboard
data class Queue(val index: Int, val canUndo: Boolean, val canRedo: Boolean)

Undo/redo queue representation

Properties

Link copied to clipboard

Whether the plugin can redo at this moment.

Link copied to clipboard

Whether the plugin can undo at this moment.

Link copied to clipboard
val index: StateFlow<Int>

Current index of the queue.

Link copied to clipboard

Whether the event queue is empty. Does not take Queue.index into account

Link copied to clipboard

Current state of the Queue. For synchronous / initial queue value access, see canUndo, canRedo, queueSize

Link copied to clipboard

The current queue size of the plugin. This queue size does not consider current index and allows to get the total amount of events stored

Functions

Link copied to clipboard
suspend operator fun <I : MVIIntent> IntentReceiver<I>.invoke(intent: I, undo: suspend () -> Unit): Int

Add the intent to the queue with specified undo and immediately execute the intent. You cannot call UndoRedo.undo or UndoRedo.redo in intent or undo!

suspend operator fun invoke(doImmediately: Boolean = true, redo: suspend () -> Unit, undo: suspend () -> Unit): Int

Add a given undo and redo to the queue. If doImmediately is true, then redo will be executed before the queue is modified! You cannot call UndoRedo.undo or UndoRedo.redo in redo or undo!

Link copied to clipboard
suspend fun redo(require: Boolean = false): Int

Redo the event at current _index. You cannot undo and redo while another undo/redo is running!

Link copied to clipboard
fun reset()

Clear the queue of events and reset _index to -1

Link copied to clipboard
suspend fun undo(require: Boolean = false): Int

Undo the event at current _index. You cannot undo and redo while another undo/redo is running!