 
   constructor: (@buffer, @undoStack=[], @redoStack=[]) ->
 
+  # Private: Used by {Serializable} during serialization
   serializeParams: ->
     undoStack: @undoStack.map (patch) -> patch.serialize()
     redoStack: @redoStack.map (patch) -> patch.serialize()
 
+  # Private: Used by {Serializable} during deserialization
   deserializeParams: (params) ->
     params.undoStack = params.undoStack.map (patchState) => @constructor.deserialize(patchState)
     params.redoStack = params.redoStack.map (patchState) => @constructor.deserialize(patchState)
     params
 
+  # Private: Called by {TextBuffer} to store a patch in the undo stack. Clears
+  # the redo stack
   recordNewPatch: (patch) ->
     if @currentTransaction?
       @currentTransaction.push(patch)

      else
        throw error

  beginTransaction: ->
    if ++@transactionDepth is 1
      @currentTransaction = new Transaction()

  commitTransaction: ->
    if --@transactionDepth is 0
      @undoStack.push(@currentTransaction) if @currentTransaction.hasBufferPatches()
      @currentTransaction = null

  abortTransaction: ->
    if @transactCallDepth is 0
      inverse = @currentTransaction.invert(@buffer)


TransactionAborted = new Error("Transaction Aborted")

# Private: Manages undo/redo for {TextBuffer}
module.exports =
class History extends Serializable
  @registerDeserializers(Transaction, BufferPatch)
