Add more debug log lines

This commit is contained in:
James Allen 2016-05-27 14:14:08 +01:00
parent fec3266726
commit 36c8c197e1
2 changed files with 12 additions and 0 deletions

View file

@ -6,7 +6,10 @@ define [
@getDocument: (ide, doc_id) -> @getDocument: (ide, doc_id) ->
@openDocs ||= {} @openDocs ||= {}
if !@openDocs[doc_id]? if !@openDocs[doc_id]?
sl_console.log "[getDocument] Creating new document instance for #{doc_id}"
@openDocs[doc_id] = new Document(ide, doc_id) @openDocs[doc_id] = new Document(ide, doc_id)
else
sl_console.log "[getDocument] Returning existing document instance for #{doc_id}"
return @openDocs[doc_id] return @openDocs[doc_id]
@hasUnsavedChanges: () -> @hasUnsavedChanges: () ->
@ -107,11 +110,14 @@ define [
@wantToBeJoined = false @wantToBeJoined = false
@_cancelJoin() @_cancelJoin()
if (@doc? and @doc.hasBufferedOps()) if (@doc? and @doc.hasBufferedOps())
sl_console.log "[leave] Doc has buffered ops, pushing callback for later"
@_leaveCallbacks ||= [] @_leaveCallbacks ||= []
@_leaveCallbacks.push callback @_leaveCallbacks.push callback
else if !@connected else if !@connected
sl_console.log "[leave] Not connected, returning now"
callback() callback()
else else
sl_console.log "[leave] Leaving now"
@_leaveDoc(callback) @_leaveDoc(callback)
flush: () -> flush: () ->
@ -202,6 +208,7 @@ define [
@connected = true @connected = true
if @wantToBeJoined or @doc?.hasBufferedOps() if @wantToBeJoined or @doc?.hasBufferedOps()
sl_console.log "[onReconnect] Rejoining (wantToBeJoined: #{@wantToBeJoined} OR hasBufferedOps: #{@doc?.hasBufferedOps()})"
@_joinDoc (error) => @_joinDoc (error) =>
return @_onError(error) if error? return @_onError(error) if error?
@doc.updateConnectionState "ok" @doc.updateConnectionState "ok"
@ -229,10 +236,12 @@ define [
callback() callback()
_leaveDoc: (callback = (error) ->) -> _leaveDoc: (callback = (error) ->) ->
sl_console.log '[_leaveDoc] Sending leaveDoc request'
@ide.socket.emit 'leaveDoc', @doc_id, (error) => @ide.socket.emit 'leaveDoc', @doc_id, (error) =>
return callback(error) if error? return callback(error) if error?
@joined = false @joined = false
for callback in @_leaveCallbacks or [] for callback in @_leaveCallbacks or []
sl_console.log '[_leaveDoc] Calling buffered callback', callback
callback(error) callback(error)
delete @_leaveCallbacks delete @_leaveCallbacks
callback(error) callback(error)

View file

@ -41,6 +41,7 @@ define [
@openDoc(doc) @openDoc(doc)
openDoc: (doc, options = {}) -> openDoc: (doc, options = {}) ->
sl_console.log "[openDoc] Opening #{doc.id}"
@$scope.ui.view = "editor" @$scope.ui.view = "editor"
done = () => done = () =>
@ -74,8 +75,10 @@ define [
done() done()
_openNewDocument: (doc, callback = (error, sharejs_doc) ->) -> _openNewDocument: (doc, callback = (error, sharejs_doc) ->) ->
sl_console.log "[_openNewDocument] Opening..."
current_sharejs_doc = @$scope.editor.sharejs_doc current_sharejs_doc = @$scope.editor.sharejs_doc
if current_sharejs_doc? if current_sharejs_doc?
sl_console.log "[_openNewDocument] Leaving existing open doc..."
current_sharejs_doc.leaveAndCleanUp() current_sharejs_doc.leaveAndCleanUp()
@_unbindFromDocumentEvents(current_sharejs_doc) @_unbindFromDocumentEvents(current_sharejs_doc)