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:
parent
7d64dbf19c
commit
06f6aa7a00
@ -23,6 +23,7 @@ const autoFaucet = require('./lib/auto-faucet')
|
|||||||
const nodeify = require('./lib/nodeify')
|
const nodeify = require('./lib/nodeify')
|
||||||
const accountImporter = require('./account-import-strategies')
|
const accountImporter = require('./account-import-strategies')
|
||||||
const getBuyEthUrl = require('./lib/buy-eth-url')
|
const getBuyEthUrl = require('./lib/buy-eth-url')
|
||||||
|
const debounce = require('debounce')
|
||||||
|
|
||||||
const version = require('../manifest.json').version
|
const version = require('../manifest.json').version
|
||||||
|
|
||||||
@ -30,6 +31,9 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
|
|
||||||
constructor (opts) {
|
constructor (opts) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
this.sendUpdate = debounce(this.privateSendUpdate.bind(this), 200)
|
||||||
|
|
||||||
this.opts = opts
|
this.opts = opts
|
||||||
const initState = opts.initState || {}
|
const initState = opts.initState || {}
|
||||||
|
|
||||||
@ -354,7 +358,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
sendUpdate () {
|
privateSendUpdate () {
|
||||||
this.emit('update', this.getState())
|
this.emit('update', this.getState())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user