Asynchronous version of DataBoard.forceSync.
This commit is contained in:
parent
f924beb280
commit
fbee3c2df2
@ -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
|
||||||
|
|||||||
@ -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}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user