new UndoObject(properties)
Creates a new undoable object.
Parameters:
| Name | Type | Description |
|---|---|---|
properties |
object | A simple POJO containing the properties to monitor. |
Members
-
:object
properties
-
Store the properties being monitored.
Type
- object
-
:object
references
-
Store a reference copy of the given properties.
Type
- object
Methods
-
addProperty(propName, value)
-
Adds a new property with the given value to both the properties and references store.
Parameters:
Name Type Description propNamestring The name of the new property to set the value of.
valueany The value to set the new property to.
Returns:
Returns this instance to support method chaining.
- Type
- PD.UndoObject
-
commitChange(propName, newValue)
-
Sets the value of a property and immediately commits the change.
Parameters:
Name Type Description propNamestring The name of the property to set the value of.
newValueany The value to set the property to.
Returns:
Returns this instance to support method chaining.
- Type
- PD.UndoObject
-
commitChanges()
-
Compares and updates the monitored properties with their reference values.
This method first compares the properties to their reference values and generates an object containing any differences. If there are any differences, it updates the reference values and then creates an new undo/redo entry containing any differences.
Returns:
Returns this instance to support method chaining.
- Type
- PD.UndoObject
-
redo(changes)
-
Copies new values in the change list to both the references and properties store.
This method is typically called by
PD.GlobalUnoas it stores the change lists corresponding to a particular undo/redo step.Parameters:
Name Type Description changesobject The results of
PD.GlobalUndo.shallowDifforPD.GlobalUndo.deepDiff. -
setProperty(path, value)
-
Sets the value of a property without committing the change.
To access the properties of child objects, you can use a nested path. A nested path may contain one or more period ('.') characters that separate it into a hierarchy of parent/child objects. If the path does not contain a period, then the whole string is treated as the field name.
As objects and arrays in JavaScript behave in some ways similar, you can use nested properties to access array entries by simply using a number as the field name to represent the ordinal index you want.
Once you have made all the changes you want to one or more properties, call the
PD.UndoObject#commitChangesmethod to store your changes as a single undo/redo entry.Parameters:
Name Type Description pathstring The path/name of the property to set the value of.
valueany The value to set the property to.
Returns:
Returns this instance to support method chaining.
- Type
- PD.UndoObject
-
undo(changes)
-
Copies new values in the change list to both the references and properties store.
This method is typically called by
PD.GlobalUnoas it stores the change lists corresponding to a particular undo/redo step.Parameters:
Name Type Description changesobject The results of
PD.GlobalUndo.shallowDifforPD.GlobalUndo.deepDiff. -
copyNewValues(changes, refObj [, newObj]) <static>
-
Recursively copies new diff changes to a reference object.
Parameters:
Name Type Argument Description changesobject The results of
PD.GlobalUndo.shallowDifforPD.GlobalUndo.deepDiff.refObjobject The references object to copy old diff change values to.
newObjobject <optional>
An optional properties object to copy new diff change values to.
-
copyOldValues(changes, refObj [, newObj]) <static>
-
Recursively copies previous diff changes to a reference object.
Parameters:
Name Type Argument Description changesobject The results of
PD.GlobalUndo.shallowDifforPD.GlobalUndo.deepDiff.refObjobject The references object to copy old diff change values to.
newObjobject <optional>
An optional properties object to copy old diff change values to.