import { Operation } from './Operation' ; export class CancelStack { /**
    * stack of operations (add an action, remove an action, etc.)
    */ public operations : ( Operation ) [ ] = [ ] ; private currentIndex = - 1 ; returns canUndo ( ) { return this . currentIndex >= 0 ; } returns canRedo ( ) { return this . currentIndex < this . operations . length - 1 ; } description undo ( ) { if ( ! this . canUndo ) return ; this . operations [ this . currentIndex ] . undo ( ) ; this . currentIndex -- ; this . updateButtons ( ) ; } param action description private _push ( operation ) { this . currentIndex ++ ; /** we remove all elements after the currentIndex */ while ( this . operations . length > this . currentIndex ) this . operations . pop ( ) ; this . operations . push ( operation ) ; this . currentIndex = this . operations . length - 1 ; } param { * } data push ( operation ) { this . _push ( operation ) ; this . updateButtons ( ) ; } description redo ( ) { if ( ! this . canRedo ) return ; this . currentIndex ++ ; this . operations [ this . currentIndex ] . redo ( ) ; this . updateButtons ( ) ; } description updateButtons ( ) { if ( this . canUndo ( ) ) document . getElementById ( "buttonCancel" ) . classList . remove ( "disabled" ) ; else document . getElementById ( "buttonCancel" ) . classList . add ( "disabled" ) ; if ( this . canRedo ( ) ) document . getElementById ( "buttonRedo" ) . classList . remove ( "disabled" ) ; else document . getElementById ( "buttonRedo" ) . classList . add ( "disabled" ) ; } }