mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-09 09:16:13 +00:00
prevent $scope.$apply from firing on every unsaved files check
only trigger a digest when there is a change in the saved state
This commit is contained in:
parent
b407fde6e3
commit
0453c657da
1 changed files with 10 additions and 6 deletions
|
@ -3,7 +3,7 @@ define [
|
|||
"ide/editor/Document"
|
||||
], (App, Document) ->
|
||||
App.controller "SavingNotificationController", ["$scope", "$interval", "ide", ($scope, $interval, ide) ->
|
||||
$interval () ->
|
||||
setInterval () ->
|
||||
pollSavedStatus()
|
||||
, 1000
|
||||
|
||||
|
@ -13,21 +13,25 @@ define [
|
|||
$scope.docSavingStatus = {}
|
||||
pollSavedStatus = () ->
|
||||
oldStatus = $scope.docSavingStatus
|
||||
$scope.docSavingStatus = {}
|
||||
newStatus = {}
|
||||
|
||||
for doc_id, doc of Document.openDocs
|
||||
saving = doc.pollSavedStatus()
|
||||
if !saving
|
||||
if oldStatus[doc_id]?
|
||||
$scope.docSavingStatus[doc_id] = oldStatus[doc_id]
|
||||
$scope.docSavingStatus[doc_id].unsavedSeconds += 1
|
||||
newStatus[doc_id] = oldStatus[doc_id]
|
||||
newStatus[doc_id].unsavedSeconds += 1
|
||||
else
|
||||
$scope.docSavingStatus[doc_id] = {
|
||||
newStatus[doc_id] = {
|
||||
unsavedSeconds: 0
|
||||
doc: ide.fileTreeManager.findEntityById(doc_id)
|
||||
}
|
||||
|
||||
if _.size(newStatus) or _.size(oldStatus)
|
||||
$scope.docSavingStatus = newStatus
|
||||
$scope.$apply()
|
||||
|
||||
warnAboutUnsavedChanges = () ->
|
||||
if Document.hasUnsavedChanges()
|
||||
return "You have unsaved changes. If you leave now they will not be saved."
|
||||
]
|
||||
]
|
||||
|
|
Loading…
Add table
Reference in a new issue