@zeainc/zea-ux
Version:
97 lines • 4.34 kB
TypeScript
import { EventEmitter } from '@zeainc/zea-engine';
import { Change } from '.';
/**
* `UndoRedoManager` is a mixture of the [Factory Design Pattern](https://en.wikipedia.org/wiki/Factory_method_pattern) and the actual changes stacks manager.
* This is the heart of the Undo/Redo System, letting you navigate through the changes history you've saved.
*
* **Events**
* * **changeAdded:** Triggered when a change is added.
* * **changeUpdated:** Triggered when the last change added updates its state.
* * **changeUndone:** Triggered when the `undo` method is called, after removing the last change from the stack.
* * **changeRedone:** Triggered when the `redo` method is called, after restoring the last change removed from the undo stack.
* */
declare class UndoRedoManager extends EventEmitter {
__undoStack: Change[];
__redoStack: Change[];
__currChange: Change | null;
/**
* It doesn't have any parameters, but under the hood it uses [EventsEmitter]() to notify subscribers when something happens.
* The implementation is really simple, just initialize it like any other class.
*/
constructor();
/**
* As the name indicates, it empties undo/redo stacks permanently, losing all stored actions.
* Right now, before flushing the stacks it calls the `destroy` method on all changes, ensure to at least declare it.
*/
flush(): void;
/**
* Receives an instance of a class that extends or has the same structure as `Change` class.
* When this action happens, the last added change update notifications will get disconnected.
* Which implies that any future updates to changes that are not the last one, would need a new call to the `addChange` method.
* Also, resets the redo stack(Calls destroy method when doing it).
*
* @param change - The change param.
*/
addChange(change: Change): void;
/**
* Returns the last change added to the undo stack, but in case it is empty a `null` is returned.
*
* @return {Change|null} The return value.
*/
getCurrentChange(): Change | null;
/**
* @param updateData
*/
private currChangeUpdated;
/**
* Rollback the latest action, passing it to the redo stack in case you wanna recover it later on.
* Emits the `changeRedone` event, passing the change
* @param pushOnRedoStack - The pushOnRedoStack param.
*/
undo(pushOnRedoStack?: boolean): void;
/**
* Method to cancel the current change added to the UndoRedoManager.
* Reverts the change and discards it.
*/
cancel(): void;
/**
* Rollbacks the `undo` action by moving the change from the `redo` stack to the `undo` stack.
* Emits the `changeRedone` event, passing the change in the event, if you want to subscribe to it.
*/
redo(): void;
/**
* Basically returns a new instance of the derived `Change` class. This is why we need the `name` attribute.
*
* @param className - The className param.
* @return - The return value.
*/
constructChange(className: string): Change;
/**
* Checks if a class of an instantiated object is registered in the UndoRedo Factory.
*
* @param inst - The instance of the Change class.
* @return {boolean} - Returns 'true' if the class has been registered.
*/
static isChangeClassRegistered(inst: Change): boolean;
/**
* Very simple method that returns the name of the instantiated class, checking first in the registry and returning if found,
* if not then checks the `name` attribute declared in constructor.
*
* @param inst - The instance of the Change class.
* @return {string} - The return value.
*/
static getChangeClassName(inst: Change): string;
/**
* Registers the class in the UndoRedoManager Factory.
* Why do we need to specify the name of the class?
* Because when the code is transpiled, the defined class names change, so it won't be known as we declared it anymore.
*
* @param name - The name param.
* @param cls - The cls param.
*/
static registerChange(name: string, cls: any): void;
static getInstance(): UndoRedoManager;
}
export default UndoRedoManager;
export { UndoRedoManager };
//# sourceMappingURL=UndoRedoManager.d.ts.map