This interface provides access to the memento design pattern to provide undoability for arbitrary models.
Remarks
By implementing this interface as well as ILookup, clients can add undoability for changes to their model classes. The yFiles undo mechanism uses the return value of getState to retrieve a state of an item at the beginning of the compound editing process. When the process ends, another state will be retrieved of the same item and compared to the original state. If they differ, an IUndoUnit is created that uses the applyState method to apply either state to the item in case of undo or redo. This represents an abstraction to the undo mechanism where it is only needed to define "states" of items and hides the more complicated mechanism of creating and inserting IUndoUnits.
The following is an example implementation of an item that is being managed using IMementoSupport:
A collection of items from this type can then be watched using the following code snippet:
Implementing the IMementoSupport interface is quite unrestrained, the type of the state returned by getState method can by anything as long as the applyState and stateEquals methods can deal with it:
In summary, use this concept when you want to track the state of items during certain operations for undo/redo. This is efficient if it's easier to handle an item's state than the changes to the item themselves. If you want to focus on the changes or on certain events, you should use custom IUndoUnit implementations instead.
Type Details
- yfiles module
- view-component
- yfiles-umd modules
- All view modules
- Legacy UMD name
- yfiles.graph.IMementoSupport
See Also
Methods
Reapplies a previously queried state object to a given subject.
Retrieves an object representing the state at the moment this method is called.
Remarks
Parameters
A map of options to pass to the method.
- subject - Object
- The subject to read the state from
Returns
- ↪any
- An object that describes the current state of
subject
.
See Also
Determines whether two state objects are equal.
Remarks
false
, an IUndoUnit is created for the two states that can reapply either state (for either undo or redo). If this method returns true
the state is considered not to have changed and no undo unit will be created. Conservative implementations my simply return false
.Parameters
A map of options to pass to the method.
- state1 - Object
- The first state as obtained from getState
- state2 - Object
- The second state as obtained from getState
Returns
- ↪boolean
true
if the states are equal;false
otherwise.
See Also
Static Methods
Creates an implementation of the interface IMementoSupport from the given definition.
Remarks
Parameters
A map of options to pass to the method.
- getState - function(any):any
Retrieves an object representing the state at the moment this method is called.
This property holds the implementation for getState.
- applyState - function(any, any):void
Reapplies a previously queried state object to a given subject.
This property holds the implementation for applyState.
- stateEquals - function(any, any):boolean
Determines whether two state objects are equal.
This property holds the implementation for stateEquals.
Returns
- ↪IMementoSupport
- An instance of the IMementoSupport interface based on the given definition.