Просмотр исходного кода

Don't do a scope.apply on every change

James Allen 12 лет назад
Родитель
Сommit
f2b8a5971f

+ 4 - 3
services/web/public/coffee/ide/connection/ConnectionManager.coffee

@@ -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

+ 0 - 5
services/web/public/coffee/ide/editor/EditorManager.coffee

@@ -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()
 

+ 1 - 4
services/web/public/coffee/ide/editor/directives/aceEditor.coffee

@@ -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