Queue callbacks from $.cache so any errors don't break setting req.evt / calling other callbacks.
This commit is contained in:
parent
6877ddce7f
commit
f32f0bb77d
@ -86,7 +86,7 @@ do ->
|
|||||||
$.cache = (url, cb, options) ->
|
$.cache = (url, cb, options) ->
|
||||||
if req = reqs[url]
|
if req = reqs[url]
|
||||||
if req.readyState is 4
|
if req.readyState is 4
|
||||||
$.queueTask -> cb.call req, req.evt
|
$.queueTask -> cb.call req, req.evt, true
|
||||||
else
|
else
|
||||||
req.callbacks.push cb
|
req.callbacks.push cb
|
||||||
return req
|
return req
|
||||||
@ -96,9 +96,9 @@ do ->
|
|||||||
catch err
|
catch err
|
||||||
return
|
return
|
||||||
$.on req, 'load', (e) ->
|
$.on req, 'load', (e) ->
|
||||||
cb.call @, e for cb in @callbacks
|
|
||||||
@evt = e
|
@evt = e
|
||||||
@cached = true
|
for cb in @callbacks
|
||||||
|
$.queueTask => cb.call @, e, false
|
||||||
delete @callbacks
|
delete @callbacks
|
||||||
$.on req, 'abort error', rm
|
$.on req, 'abort error', rm
|
||||||
req.callbacks = [cb]
|
req.callbacks = [cb]
|
||||||
|
|||||||
@ -6,8 +6,8 @@ class Fetcher
|
|||||||
|
|
||||||
@root.textContent = "Loading post No.#{@postID}..."
|
@root.textContent = "Loading post No.#{@postID}..."
|
||||||
if @threadID
|
if @threadID
|
||||||
$.cache "//a.4cdn.org/#{@boardID}/thread/#{@threadID}.json", (e) =>
|
$.cache "//a.4cdn.org/#{@boardID}/thread/#{@threadID}.json", (e, isCached) =>
|
||||||
@fetchedPost e.target
|
@fetchedPost e.target, isCached
|
||||||
else
|
else
|
||||||
@archivedPost()
|
@archivedPost()
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ class Fetcher
|
|||||||
$.add @root, nodes.root
|
$.add @root, nodes.root
|
||||||
$.event 'PostsInserted'
|
$.event 'PostsInserted'
|
||||||
|
|
||||||
fetchedPost: (req) ->
|
fetchedPost: (req, isCached) ->
|
||||||
# In case of multiple callbacks for the same request,
|
# In case of multiple callbacks for the same request,
|
||||||
# don't parse the same original post more than once.
|
# don't parse the same original post more than once.
|
||||||
if post = g.posts["#{@boardID}.#{@postID}"]
|
if post = g.posts["#{@boardID}.#{@postID}"]
|
||||||
@ -59,11 +59,11 @@ class Fetcher
|
|||||||
|
|
||||||
if post.no isnt @postID
|
if post.no isnt @postID
|
||||||
# Cached requests can be stale and must be rechecked.
|
# Cached requests can be stale and must be rechecked.
|
||||||
if req.cached
|
if isCached
|
||||||
api = "//a.4cdn.org/#{@boardID}/thread/#{@threadID}.json"
|
api = "//a.4cdn.org/#{@boardID}/thread/#{@threadID}.json"
|
||||||
$.cleanCache (url) -> url is api
|
$.cleanCache (url) -> url is api
|
||||||
$.cache api, (e) =>
|
$.cache api, (e) =>
|
||||||
@fetchedPost e.target
|
@fetchedPost e.target, false
|
||||||
return
|
return
|
||||||
|
|
||||||
# The post can be deleted by the time we check a quote.
|
# The post can be deleted by the time we check a quote.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user