From d32e9c8ef641f582a36c13d23e89c41050bb5d2d Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 26 Apr 2013 02:07:57 +0200 Subject: [PATCH] Debounce $.set on Chrome. Should help #1018. --- lib/$.coffee | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/$.coffee b/lib/$.coffee index 2ea705662..35b077f03 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -232,12 +232,22 @@ $.get = (key, val, cb) -> items = key cb = val chrome.storage.sync.get items, cb -$.set = (key, val) -> - items = if typeof key is 'string' - $.item key, val - else - key - chrome.storage.sync.set items +$.set = do -> + items = {} + + set = $.debounce 500, -> + try + chrome.storage.sync.set items + items = {} + catch err + c.error err + + (key, val) -> + if typeof key is 'string' + items[key] = val + else + $.extend items, key + set() <% } else if (type === 'userjs') { %> do -> # http://www.opera.com/docs/userjs/specs/#scriptstorage