mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Extract debounced load to service, so can be injected
This commit is contained in:
parent
1f9c1ca6c6
commit
b2abcfc3f2
2 changed files with 17 additions and 20 deletions
|
@ -53,31 +53,12 @@ define [
|
|||
lastCommandFragmentIsReqPack
|
||||
|
||||
if linesContainMeta or lastCommandFragmentIsMeta
|
||||
@scheduleLoadCurrentDocMetaFromServer()
|
||||
@Metadata.scheduleLoadDocMetaFromServer @$scope.docId
|
||||
|
||||
@editor.on "changeSession", (e) =>
|
||||
e.oldSession.off "change", onChange
|
||||
e.session.on "change", onChange
|
||||
|
||||
|
||||
loadDocMetaFromServer: (docId) ->
|
||||
@Metadata.loadDocMetaFromServer docId
|
||||
|
||||
scheduleLoadCurrentDocMetaFromServer: () ->
|
||||
# De-bounce loading labels with a timeout
|
||||
currentDocId = @$scope.docId
|
||||
existingTimeout = @debouncer[currentDocId]
|
||||
if existingTimeout?
|
||||
clearTimeout(existingTimeout)
|
||||
delete @debouncer[currentDocId]
|
||||
@debouncer[currentDocId] = setTimeout(
|
||||
() =>
|
||||
@loadDocMetaFromServer currentDocId
|
||||
delete @debouncer[currentDocId]
|
||||
, 1000
|
||||
, this
|
||||
)
|
||||
|
||||
getAllLabels: () ->
|
||||
@Metadata.getAllLabels()
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ define [
|
|||
], (App) ->
|
||||
|
||||
App.factory 'metadata', ($http, ide) ->
|
||||
debouncer = {} # DocId => Timeout
|
||||
|
||||
state = {documents: {}}
|
||||
|
||||
|
@ -46,4 +47,19 @@ define [
|
|||
{_csrf: window.csrfToken}
|
||||
)
|
||||
|
||||
metadata.scheduleLoadDocMetaFromServer = (docId) ->
|
||||
# De-bounce loading labels with a timeout
|
||||
existingTimeout = debouncer[docId]
|
||||
|
||||
if existingTimeout?
|
||||
clearTimeout(existingTimeout)
|
||||
delete debouncer[docId]
|
||||
|
||||
debouncer[docId] = setTimeout(
|
||||
() =>
|
||||
metadata.loadDocMetaFromServer docId
|
||||
delete debouncer[docId]
|
||||
, 1000
|
||||
)
|
||||
|
||||
return metadata
|
||||
|
|
Loading…
Reference in a new issue