Don't do a scope.apply on every change

This commit is contained in:
James Allen 2014-07-09 20:32:03 +01:00
parent 558d32adeb
commit f2b8a5971f
3 changed files with 5 additions and 12 deletions

View file

@ -11,6 +11,9 @@ define [], () ->
@$scope.tryReconnectNow = () =>
@tryReconnect()
@$scope.$on "editor:change", () =>
@lastUpdated = new Date()
@ide.socket = io.connect null,
reconnect: false
"force new connection": true
@ -70,10 +73,8 @@ define [], () ->
@ide.socket.disconnect()
startAutoReconnectCountdown: () ->
lastUpdated = @ide.editorManager.lastUpdated()
twoMinutes = 2 * 60 * 1000
if lastUpdated? and new Date() - lastUpdated > twoMinutes
if @lastUpdated? and new Date() - @lastUpdated > twoMinutes
# between 1 minute and 3 minutes
countdown = 60 + Math.floor(Math.random() * 120)
else

View file

@ -7,10 +7,8 @@ define [
constructor: (@ide, @$scope) ->
@$scope.editor = {
sharejs_doc: null
last_updated: null
open_doc_id: null
opening: true
cursorPosition: {}
gotoLine: null
}
@ -93,9 +91,6 @@ define [
_unbindFromDocumentEvents: (document) ->
document.off()
lastUpdated: () ->
@$scope.editor.last_updated
getCurrentDocValue: () ->
@$scope.editor.sharejs_doc?.getSnapshot()

View file

@ -18,9 +18,7 @@ define [
fontSize: "="
autoComplete: "="
sharejsDoc: "="
lastUpdated: "="
spellCheckLanguage: "="
cursorPosition: "="
highlights: "="
text: "="
readOnly: "="
@ -117,8 +115,7 @@ define [
doc = session.getDocument()
doc.on "change", () ->
scope.$apply () ->
scope.lastUpdated = new Date()
scope.$emit "#{scope.name}:change"
sharejs_doc.on "remoteop.recordForUndo", () =>
undoManager.nextUpdateIsRemote = true