mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Add ViewRegistry.prototype.getNextUpdatePromise
Signed-off-by: Max Brunsfeld <maxbrunsfeld@github.com>
This commit is contained in:
@@ -209,3 +209,21 @@ describe "ViewRegistry", ->
|
||||
window.dispatchEvent(new UIEvent('resize'))
|
||||
|
||||
expect(events).toEqual ['poll 1', 'poll 2']
|
||||
|
||||
describe "::getNextUpdatePromise()", ->
|
||||
it "returns a promise that resolves at the end of the next update cycle", ->
|
||||
updateCalled = false
|
||||
readCalled = false
|
||||
pollCalled = false
|
||||
|
||||
waitsFor 'getNextUpdatePromise to resolve', (done) ->
|
||||
registry.getNextUpdatePromise().then ->
|
||||
expect(updateCalled).toBe true
|
||||
expect(readCalled).toBe true
|
||||
expect(pollCalled).toBe true
|
||||
done()
|
||||
|
||||
registry.updateDocument -> updateCalled = true
|
||||
registry.readDocument -> readCalled = true
|
||||
registry.pollDocument -> pollCalled = true
|
||||
registry.pollAfterNextUpdate()
|
||||
|
||||
@@ -195,6 +195,10 @@ class ViewRegistry
|
||||
pollAfterNextUpdate: ->
|
||||
@performDocumentPollAfterUpdate = true
|
||||
|
||||
getNextUpdatePromise: ->
|
||||
@nextUpdatePromise ?= new Promise (resolve) =>
|
||||
@resolveNextUpdatePromise = resolve
|
||||
|
||||
clearDocumentRequests: ->
|
||||
@documentReaders = []
|
||||
@documentWriters = []
|
||||
@@ -220,6 +224,9 @@ class ViewRegistry
|
||||
# process updates requested as a result of reads
|
||||
writer() while writer = @documentWriters.shift()
|
||||
|
||||
@nextUpdatePromise = null
|
||||
@resolveNextUpdatePromise?()
|
||||
|
||||
startPollingDocument: ->
|
||||
window.addEventListener('resize', @requestDocumentPoll)
|
||||
@observer.observe(document, {subtree: true, childList: true, attributes: true})
|
||||
|
||||
Reference in New Issue
Block a user