aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-06-16 09:00:24 +0800
committerDan Finlay <dan@danfinlay.com>2017-06-16 09:01:10 +0800
commit06f6aa7a00f57004746d1e21759ac56396d9b855 (patch)
tree999fc2fd4145dc484d756612671d177fa895fcdb
parent7d64dbf19cc6a9e4699af92097be3f88a16d3d35 (diff)
downloadtangerine-wallet-browser-06f6aa7a00f57004746d1e21759ac56396d9b855.tar
tangerine-wallet-browser-06f6aa7a00f57004746d1e21759ac56396d9b855.tar.gz
tangerine-wallet-browser-06f6aa7a00f57004746d1e21759ac56396d9b855.tar.bz2
tangerine-wallet-browser-06f6aa7a00f57004746d1e21759ac56396d9b855.tar.lz
tangerine-wallet-browser-06f6aa7a00f57004746d1e21759ac56396d9b855.tar.xz
tangerine-wallet-browser-06f6aa7a00f57004746d1e21759ac56396d9b855.tar.zst
tangerine-wallet-browser-06f6aa7a00f57004746d1e21759ac56396d9b855.zip
Debounce background updates
Our background sometimes emits absurd quantities of updates very quickly. This PR reduces the amount of inter-process traffic by ensuring the `sendUpdate` method does not fire more than every 200 ms. Fixes #1621
-rw-r--r--app/scripts/metamask-controller.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index a7eb3d056..d745d29dc 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -23,6 +23,7 @@ const autoFaucet = require('./lib/auto-faucet')
const nodeify = require('./lib/nodeify')
const accountImporter = require('./account-import-strategies')
const getBuyEthUrl = require('./lib/buy-eth-url')
+const debounce = require('debounce')
const version = require('../manifest.json').version
@@ -30,6 +31,9 @@ module.exports = class MetamaskController extends EventEmitter {
constructor (opts) {
super()
+
+ this.sendUpdate = debounce(this.privateSendUpdate.bind(this), 200)
+
this.opts = opts
const initState = opts.initState || {}
@@ -354,7 +358,7 @@ module.exports = class MetamaskController extends EventEmitter {
)
}
- sendUpdate () {
+ privateSendUpdate () {
this.emit('update', this.getState())
}