Asynchronous version of DataBoard.forceSync.

This commit is contained in:
ccd0 2017-12-10 22:26:43 -08:00
parent f924beb280
commit fbee3c2df2
2 changed files with 19 additions and 10 deletions

View File

@ -196,13 +196,15 @@ ThreadWatcher =
ThreadWatcher.fetchAllStatus() ThreadWatcher.fetchAllStatus()
fetchAllStatus: -> fetchAllStatus: ->
ThreadWatcher.db.forceSync() dbs = [ThreadWatcher.db, ThreadWatcher.unreaddb, QuoteYou.db].filter((x) -> x)
ThreadWatcher.unreaddb.forceSync() n = 0
QuoteYou.db?.forceSync() for db in dbs
return unless (threads = ThreadWatcher.getAll()).length db.forceSync ->
for thread in threads if (++n) is dbs.length
ThreadWatcher.fetchStatus thread threads = ThreadWatcher.getAll()
return for thread in threads
ThreadWatcher.fetchStatus thread
return
fetchStatus: (thread, force) -> fetchStatus: (thread, force) ->
{boardID, threadID, data} = thread {boardID, threadID, data} = thread

View File

@ -29,6 +29,16 @@ class DataBoard
@sync?() if snapshot1 isnt snapshot2 @sync?() if snapshot1 isnt snapshot2
cb?() cb?()
forceSync: (cb) ->
snapshot1 = JSON.stringify @data
{changes} = @
$.get @key, {boards: {}}, (items) =>
@data = items[@key]
snapshot2 = JSON.stringify @data
c() for c in changes
@sync?() if snapshot1 isnt snapshot2
cb?()
delete: ({boardID, threadID, postID}) -> delete: ({boardID, threadID, postID}) ->
@save => @save =>
if postID if postID
@ -92,9 +102,6 @@ class DataBoard
thread thread
val or defaultValue val or defaultValue
forceSync: ->
$.forceSync @key
clean: -> clean: ->
for boardID, val of @data.boards for boardID, val of @data.boards
@deleteIfEmpty {boardID} @deleteIfEmpty {boardID}