Class UndoManager<StateType, UndoStateType>Abstract

Type Parameters

  • StateType
  • UndoStateType

Constructors

Properties

canRedo$: Observable<boolean>

An observable that emits the result of canRedo() every time that value changes.

canUndo$: Observable<boolean>

An observable that emits the result of canUndo() every time that value changes.

maxDepth: number = 0

The maximum size of the history before discarding the oldest state. 0 means no limit.

state$: Observable<UndoStateType>

An observable that emits the current state every time it changes.

Accessors

Methods

  • Reset the store to the given state.

    The undoOrRedo and stateToOverwrite parameters can be useful e.g. if a scroll position is kept in the undo state. In such a case you want to change the scrolling so the user can see what just changed by undoing/redoing. To do that, set the scoll to what it was in stateToOverwrite when undoing, and to what it is in stateToApply when redoing.

    Parameters

    Returns void

  • Drops the state from the internal undo stack that would be applied by a call to .undo(). This is useful e.g. if making multiple changes in a row that should be collapsed into a single undo state: call this first before pushing the new version.

    Returns void

    Throws

    Error when there is no such state (i.e. when canUndo() returns false)

  • Each time a state is added to the history, this method will be called to determine whether the oldest state should be dropped. Override to implement more complex logic than the simple maxDepth.

    Parameters

    • size: number

    Returns boolean

  • Add the current state to the undo history. Any states that could be reached using redo() are discarded.

    Parameters

    • __namedParameters: {
          collectDebounce?: number;
          collectKey?: string;
      } = {}
      • Optional collectDebounce?: number
      • Optional collectKey?: string

    Returns void

  • Move forward one step in the history of states saved via pushCurrentState(), setting the store to contain that state again.

    Returns void

    Throws

    Error when there is no such state (i.e. when canRedo() returns false)

  • Used to determine whether .pushCurrentState() actually does anything. Override this e.g. to prevent pushing a duplicate undo state using something like this:

    protected shouldPush(state: UndoStateType) {
    return equal(state, this.currentUndoState);
    }

    Parameters

    Returns boolean

  • Move backward one step in the history of states saved via pushCurrentState(), setting the store to contain that state again.

    Returns void

    Throws

    Error when there is no such state (i.e. when canUndo() returns false)