import { ISharedMap , IValueChanged } from "@fluidframework/map" ; import { IRevertible , UndoRedoStackManager } from "./undoRedoStackManager" ; /**
 * A shared map undo redo handler that will add all local map changes to the provided
 * undo redo stack manager
 */ export class SharedMapUndoRedoHandler { constructor ( private readonly stackManager ) { } public attachMap ( map ) { map . on ( "valueChanged" , this . mapDeltaHandler ) ; } public detachMap ( map ) { map . off ( "valueChanged" , this . mapDeltaHandler ) ; } private readonly mapDeltaHandler = ( changed , local , target ) => { if ( local ) { this . stackManager . pushToCurrentOperation ( new SharedMapRevertible ( changed , target ) ) ; } } ; } /**
 * Tracks a change on a shared map allows reverting it
 */ export class SharedMapRevertible implements IRevertible { constructor ( private readonly changed , private readonly map ) { } public revert ( ) { this . map . set ( this . changed . key , this . changed . previousValue ) ; } public discard ( ) { return ; } }