mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
Merge branch 'sk-labels-ac-debounce'
This commit is contained in:
commit
8b7a1bd4d9
1 changed files with 12 additions and 5 deletions
|
@ -11,7 +11,7 @@ define [
|
||||||
|
|
||||||
class LabelsManager
|
class LabelsManager
|
||||||
constructor: (@$scope, @editor, @element, @Labels) ->
|
constructor: (@$scope, @editor, @element, @Labels) ->
|
||||||
@loadLabelsTimeout = null
|
@debouncer = {} # DocId => Timeout
|
||||||
|
|
||||||
onChange = (change) =>
|
onChange = (change) =>
|
||||||
if change.remote
|
if change.remote
|
||||||
|
@ -36,13 +36,20 @@ define [
|
||||||
currentDocId = @$scope.docId
|
currentDocId = @$scope.docId
|
||||||
@Labels.loadDocLabelsFromServer(currentDocId)
|
@Labels.loadDocLabelsFromServer(currentDocId)
|
||||||
|
|
||||||
|
loadDocLabelsFromServer: (docId) ->
|
||||||
|
@Labels.loadDocLabelsFromServer(docId)
|
||||||
|
|
||||||
scheduleLoadCurrentDocLabelsFromServer: () ->
|
scheduleLoadCurrentDocLabelsFromServer: () ->
|
||||||
# De-bounce loading labels with a timeout
|
# De-bounce loading labels with a timeout
|
||||||
if @loadLabelsTimeout
|
currentDocId = @$scope.docId
|
||||||
clearTimeout(@loadLabelsTimeout)
|
existingTimeout = @debouncer[currentDocId]
|
||||||
@loadLabelsTimeout = setTimeout(
|
if existingTimeout?
|
||||||
|
clearTimeout(existingTimeout)
|
||||||
|
delete @debouncer[currentDocId]
|
||||||
|
@debouncer[currentDocId] = setTimeout(
|
||||||
() =>
|
() =>
|
||||||
@loadCurrentDocLabelsFromServer()
|
@loadDocLabelsFromServer(currentDocId)
|
||||||
|
delete @debouncer[currentDocId]
|
||||||
, 1000
|
, 1000
|
||||||
, this
|
, this
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue