aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2018-01-26 05:01:03 +0800
committerDan Finlay <dan@danfinlay.com>2018-01-26 05:01:03 +0800
commitceebc6caa4f3eab1cf6c9ec8f47dc8bd450ca4a9 (patch)
tree0a9cb417d8045c45ce2c36035ae4c84e429eb8ec /app
parent2f13790653cb20d9d967700133df6cf31ff02d14 (diff)
downloadtangerine-wallet-browser-ceebc6caa4f3eab1cf6c9ec8f47dc8bd450ca4a9.tar
tangerine-wallet-browser-ceebc6caa4f3eab1cf6c9ec8f47dc8bd450ca4a9.tar.gz
tangerine-wallet-browser-ceebc6caa4f3eab1cf6c9ec8f47dc8bd450ca4a9.tar.bz2
tangerine-wallet-browser-ceebc6caa4f3eab1cf6c9ec8f47dc8bd450ca4a9.tar.lz
tangerine-wallet-browser-ceebc6caa4f3eab1cf6c9ec8f47dc8bd450ca4a9.tar.xz
tangerine-wallet-browser-ceebc6caa4f3eab1cf6c9ec8f47dc8bd450ca4a9.tar.zst
tangerine-wallet-browser-ceebc6caa4f3eab1cf6c9ec8f47dc8bd450ca4a9.zip
Debounce storage to avoid crashing pump
Diffstat (limited to 'app')
-rw-r--r--app/scripts/background.js16
1 files changed, 8 insertions, 8 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index a77763c41..2a8efd844 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -1,6 +1,7 @@
const urlUtil = require('url')
const endOfStream = require('end-of-stream')
const pump = require('pump')
+const debounce = require('debounce-stream')
const log = require('loglevel')
const extension = require('extensionizer')
const LocalStorageStore = require('obs-store/lib/localStorage')
@@ -65,11 +66,7 @@ async function loadStateFromPersistence () {
log.error('error fetching state from local store:', err)
}
- console.log('Comparing localdata and versionedData')
- console.dir({ localData })
-
if (Object.keys(localData).length > 0) {
- console.log('using the local store data')
versionedData = localData
}
}
@@ -117,8 +114,12 @@ function setupController (initState) {
// setup state persistence
pump(
asStream(controller.store),
+ debounce(200),
storeTransform(versionifyData),
storeTransform(syncDataWithExtension),
+ (error) => {
+ log.error('pump hit error', error)
+ }
)
function versionifyData (state) {
@@ -126,15 +127,14 @@ function setupController (initState) {
return versionedData
}
- function syncDataWithExtension(state) {
+ async function syncDataWithExtension(state) {
if (localStore.isSupported) {
try {
- console.log('persisting state', state)
- localStore.set(state)
+ await localStore.set(state)
} catch (err) {
log.error('error setting state in local store:', err)
}
- }
+ } else { log.error('local store not supported') }
return state
}