 
 
   create: (type, key, initialValue) ->
+
+    return null  if @isDisposed
 
     doc = @getRealtimeDoc()
 


    onLoadedCallback = (doc) =>
      doc.addEventListener gapi.drive.realtime.EventType.COLLABORATOR_JOINED, (c) =>
        @emit 'CollaboratorJoined', doc, c

      doc.addEventListener gapi.drive.realtime.EventType.COLLABORATOR_LEFT, (c) =>
        @emit 'CollaboratorLeft', doc, c

      doc.addEventListener gapi.drive.realtime.EventType.DOCUMENT_SAVE_STATE_CHANGED, (c) =>
        @emit 'DocumentSaveStateChanged', doc, c

      @emit 'FileLoaded', doc


  bindStringListeners: (string) ->

    string.addEventListener gapi.drive.realtime.EventType.TEXT_INSERTED, (e) =>
      @emit 'TextInsertedIntoString', string, e  unless @isDisposed

    string.addEventListener gapi.drive.realtime.EventType.TEXT_DELETED, (e) =>
      @emit 'TextDeletedFromString', string, e  unless @isDisposed


  bindMapListeners: (map) ->

    map.addEventListener gapi.drive.realtime.EventType.VALUE_CHANGED, (v) =>
      @emit 'MapValueChanged', map, v  unless @isDisposed


  bindListListeners: (list) ->

    list.addEventListener gapi.drive.realtime.EventType.VALUES_ADDED, (v) =>
      @emit 'ValuesAddedToList', list, v  unless @isDisposed

    list.addEventListener gapi.drive.realtime.EventType.VALUES_REMOVED, (v) =>
      @emit 'ValuesRemovedFromList', list, v  unless @isDisposed

    list.addEventListener gapi.drive.realtime.EventType.VALUES_SET, (v) =>
      @emit 'ListValuesSet', list, v  unless @isDisposed


  getCollaborators: -> return @getRealtimeDoc().getCollaborators()


  dispose: ->

    @isDisposed = yes
    @destroy()
