From cede04f144f499309ad717d628cca2ce923fed42 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 26 Apr 2013 02:24:13 +0200 Subject: [PATCH] Fix $.debounce calling the function twice. --- lib/$.coffee | 23 +++++++++++------------ src/features.coffee | 4 ++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/$.coffee b/lib/$.coffee index 35b077f03..c0c500f0e 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -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 = {} diff --git a/src/features.coffee b/src/features.coffee index d771b1df3..01dbb24b2 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -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