From f2b8a5971fa24215e9ff8f2cce3729057e4a2fbb Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 9 Jul 2014 20:32:03 +0100 Subject: [PATCH] Don't do a scope.apply on every change --- .../public/coffee/ide/connection/ConnectionManager.coffee | 7 ++++--- services/web/public/coffee/ide/editor/EditorManager.coffee | 5 ----- .../public/coffee/ide/editor/directives/aceEditor.coffee | 5 +---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/services/web/public/coffee/ide/connection/ConnectionManager.coffee b/services/web/public/coffee/ide/connection/ConnectionManager.coffee index 8046a978e7..a6031bb29d 100644 --- a/services/web/public/coffee/ide/connection/ConnectionManager.coffee +++ b/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 diff --git a/services/web/public/coffee/ide/editor/EditorManager.coffee b/services/web/public/coffee/ide/editor/EditorManager.coffee index 2eb7cd1384..1298d837e6 100644 --- a/services/web/public/coffee/ide/editor/EditorManager.coffee +++ b/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() diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index 8bbc168cfe..37bb18fd89 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/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