Fix $.debounce calling the function twice.

This commit is contained in:
Nicolas Stepien 2013-04-26 02:24:13 +02:00
parent d32e9c8ef6
commit cede04f144
2 changed files with 13 additions and 14 deletions

View File

@ -147,21 +147,20 @@ $.open = do ->
else
(URL) -> window.open URL, '_blank'
$.debounce = (wait, fn) ->
timeout = null
that = null
args = null
exec = ->
lastCall = 0
timeout = null
that = null
args = null
exec = ->
lastCall = Date.now()
fn.apply that, args
timeout = null
->
args = arguments
that = this
if timeout
# stop current reset
clearTimeout timeout
else
exec()
if lastCall < Date.now() - wait
return exec()
# stop current reset
clearTimeout timeout
# after wait, let next invocation execute immediately
timeout = setTimeout exec, wait
$.queueTask = do ->
@ -235,7 +234,7 @@ $.get = (key, val, cb) ->
$.set = do ->
items = {}
set = $.debounce 500, ->
set = $.debounce $.SECOND, ->
try
chrome.storage.sync.set items
items = {}

View File

@ -3942,9 +3942,9 @@ Unread =
Unread.readArray Unread.postsQuotingYou
Unread.update() if e
saveLastReadPost: $.debounce 2 * $.SECOND, ->
saveLastReadPost: ->
Unread.db.set
boardID: Unread.thread.board.ID
boardID: Unread.thread.board.ID
threadID: Unread.thread.ID
val: Unread.lastReadPost