Asynchronous version of DataBoard.forceSync.
This commit is contained in:
parent
f924beb280
commit
fbee3c2df2
@ -196,13 +196,15 @@ ThreadWatcher =
|
||||
ThreadWatcher.fetchAllStatus()
|
||||
|
||||
fetchAllStatus: ->
|
||||
ThreadWatcher.db.forceSync()
|
||||
ThreadWatcher.unreaddb.forceSync()
|
||||
QuoteYou.db?.forceSync()
|
||||
return unless (threads = ThreadWatcher.getAll()).length
|
||||
for thread in threads
|
||||
ThreadWatcher.fetchStatus thread
|
||||
return
|
||||
dbs = [ThreadWatcher.db, ThreadWatcher.unreaddb, QuoteYou.db].filter((x) -> x)
|
||||
n = 0
|
||||
for db in dbs
|
||||
db.forceSync ->
|
||||
if (++n) is dbs.length
|
||||
threads = ThreadWatcher.getAll()
|
||||
for thread in threads
|
||||
ThreadWatcher.fetchStatus thread
|
||||
return
|
||||
|
||||
fetchStatus: (thread, force) ->
|
||||
{boardID, threadID, data} = thread
|
||||
|
||||
@ -29,6 +29,16 @@ class DataBoard
|
||||
@sync?() if snapshot1 isnt snapshot2
|
||||
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}) ->
|
||||
@save =>
|
||||
if postID
|
||||
@ -92,9 +102,6 @@ class DataBoard
|
||||
thread
|
||||
val or defaultValue
|
||||
|
||||
forceSync: ->
|
||||
$.forceSync @key
|
||||
|
||||
clean: ->
|
||||
for boardID, val of @data.boards
|
||||
@deleteIfEmpty {boardID}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user