Undoredo.js 888 Bytes
class Undoredo {
    constructor() {
        this.undoStack = [];
        this.redoStack = [];
    }

    currentStatusPush = (data) => {
        this.undoStack.push(data);
        if (this.redoStack.length > 0) {
            this.redoStack = [];
        }
    };

    undoPush = (data) => {
        this.undoStack.push(data);
    };

    redoPush = (data) => {
        this.redoStack.push(data);
    };

    undo = () => {
        if (this.undoStack.length > 0) {
            return this.undoStack.pop();
        }
        return [];
    };

    redo = () => {
        if (this.redoStack.length > 0) {
            return this.redoStack.pop();
        }
        return [];
    };

    clear = () => {
        this.undoStack = [];
        this.redoStack = [];
    };

    isUndo = () => this.undoStack.length > 0;

    isRedo = () => this.redoStack.length > 0;
}

export default Undoredo;