1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

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
This commit is contained in:
Dan Finlay 2017-06-15 18:00:24 -07:00
parent 7d64dbf19c
commit 06f6aa7a00

View File

@ -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())
}