Undo / Redo operations
This module captures the Ctrl+Z (undo) and Ctrl+Y (redo) keys then execute the corresponding callback actions.
Members
object
# static log
Log of all the operations
Properties:
Name | Type | Description |
---|---|---|
log.undo |
array
|
List of all the undo operations |
log.redo |
array
|
List of all the redo operations |
Example
kiss.undoRedo.log.undo.push({
action: "updateField",
createdAt: new Date(),
modelId: "contact",
recordId: "01927830-96f4-7167-8aad-1608c82cc415",
fieldId: "fullname",
oldValue: "John Doe",
newValue: "John Doe Jr."
})
Methods
# static addOperation(operation)
Add an operation to the undo log
Parameters:
Name | Type | Description |
---|---|---|
operation |
object
|
Operation to add to the undo log |
# static getOperations(order) → {Array.<object>}
Get the operations from the undo log
Parameters:
Name | Type | Description |
---|---|---|
order |
string
|
Order of the operations. Use "asc" (default) or "desc" |
List of operations, in the specified order
Array.<object>
# static init(config)
Init the undo/redo module and specify the callbacks to execute when pressing Ctrl+Z or Ctrl+Y
Parameters:
Name | Type | Description |
---|---|---|
config |
object
|
|
undo |
function
|
Function to call to undo (Ctrl+Z). Can be async. |
redo |
function
|
Function to call to redo (Ctrl+Y). Can be async. |
Example
kiss.undoRedo.init({
async undo() {
// Undo code here
},
async redo() {
// Redo code here
}
})
kiss.undoRedo.undo() // Undo the last operation