Fix $.debounce calling the function twice.
This commit is contained in:
parent
d32e9c8ef6
commit
cede04f144
23
lib/$.coffee
23
lib/$.coffee
@ -147,21 +147,20 @@ $.open = do ->
|
|||||||
else
|
else
|
||||||
(URL) -> window.open URL, '_blank'
|
(URL) -> window.open URL, '_blank'
|
||||||
$.debounce = (wait, fn) ->
|
$.debounce = (wait, fn) ->
|
||||||
timeout = null
|
lastCall = 0
|
||||||
that = null
|
timeout = null
|
||||||
args = null
|
that = null
|
||||||
exec = ->
|
args = null
|
||||||
|
exec = ->
|
||||||
|
lastCall = Date.now()
|
||||||
fn.apply that, args
|
fn.apply that, args
|
||||||
timeout = null
|
|
||||||
->
|
->
|
||||||
args = arguments
|
args = arguments
|
||||||
that = this
|
that = this
|
||||||
if timeout
|
if lastCall < Date.now() - wait
|
||||||
# stop current reset
|
return exec()
|
||||||
clearTimeout timeout
|
# stop current reset
|
||||||
else
|
clearTimeout timeout
|
||||||
exec()
|
|
||||||
|
|
||||||
# after wait, let next invocation execute immediately
|
# after wait, let next invocation execute immediately
|
||||||
timeout = setTimeout exec, wait
|
timeout = setTimeout exec, wait
|
||||||
$.queueTask = do ->
|
$.queueTask = do ->
|
||||||
@ -235,7 +234,7 @@ $.get = (key, val, cb) ->
|
|||||||
$.set = do ->
|
$.set = do ->
|
||||||
items = {}
|
items = {}
|
||||||
|
|
||||||
set = $.debounce 500, ->
|
set = $.debounce $.SECOND, ->
|
||||||
try
|
try
|
||||||
chrome.storage.sync.set items
|
chrome.storage.sync.set items
|
||||||
items = {}
|
items = {}
|
||||||
|
|||||||
@ -3942,9 +3942,9 @@ Unread =
|
|||||||
Unread.readArray Unread.postsQuotingYou
|
Unread.readArray Unread.postsQuotingYou
|
||||||
Unread.update() if e
|
Unread.update() if e
|
||||||
|
|
||||||
saveLastReadPost: $.debounce 2 * $.SECOND, ->
|
saveLastReadPost: ->
|
||||||
Unread.db.set
|
Unread.db.set
|
||||||
boardID: Unread.thread.board.ID
|
boardID: Unread.thread.board.ID
|
||||||
threadID: Unread.thread.ID
|
threadID: Unread.thread.ID
|
||||||
val: Unread.lastReadPost
|
val: Unread.lastReadPost
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user