mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-27 02:51:57 +02:00
Extract debounced load to service, so can be injected
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user