diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-01-06 03:33:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-06 03:33:47 +0800 |
commit | 906c3882bb426985b403e744727f3a2071eabce7 (patch) | |
tree | adafdb919fd4ad78c23135819000199b5ea6db75 | |
parent | 3727cad0c4bbcac31030cf67a5836729e08a56d8 (diff) | |
parent | 4c1b7700adb6ac1906ef79bfd19c1402bc8ade4f (diff) | |
download | tangerine-wallet-browser-906c3882bb426985b403e744727f3a2071eabce7.tar tangerine-wallet-browser-906c3882bb426985b403e744727f3a2071eabce7.tar.gz tangerine-wallet-browser-906c3882bb426985b403e744727f3a2071eabce7.tar.bz2 tangerine-wallet-browser-906c3882bb426985b403e744727f3a2071eabce7.tar.lz tangerine-wallet-browser-906c3882bb426985b403e744727f3a2071eabce7.tar.xz tangerine-wallet-browser-906c3882bb426985b403e744727f3a2071eabce7.tar.zst tangerine-wallet-browser-906c3882bb426985b403e744727f3a2071eabce7.zip |
Merge pull request #971 from MetaMask/TearDownOnDisconnect
MetaMask Controller - Convert to EventEmitter
-rw-r--r-- | app/scripts/background.js | 9 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 10 |
2 files changed, 8 insertions, 11 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index ca2efc114..6b7926526 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -22,7 +22,6 @@ const controller = new MetamaskController({ setData, loadData, }) -const keyringController = controller.keyringController const txManager = controller.txManager function triggerUi () { if (!popupIsOpen) notification.show() @@ -81,13 +80,11 @@ function setupControllerConnection (stream) { stream.pipe(dnode).pipe(stream) dnode.on('remote', (remote) => { // push updates to popup - controller.ethStore.on('update', controller.sendUpdate.bind(controller)) - controller.listeners.push(remote) - keyringController.on('update', controller.sendUpdate.bind(controller)) - + var sendUpdate = remote.sendUpdate.bind(remote) + controller.on('update', sendUpdate) // teardown on disconnect eos(stream, () => { - controller.ethStore.removeListener('update', controller.sendUpdate.bind(controller)) + controller.removeListener('update', sendUpdate) popupIsOpen = false }) }) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 961130dfd..555460f3d 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1,3 +1,4 @@ +const EventEmitter = require('events') const extend = require('xtend') const EthStore = require('./lib/eth-store') const MetaMaskProvider = require('web3-provider-engine/zero.js') @@ -13,12 +14,12 @@ const autoFaucet = require('./lib/auto-faucet') const nodeify = require('./lib/nodeify') const IdStoreMigrator = require('./lib/idStore-migrator') -module.exports = class MetamaskController { +module.exports = class MetamaskController extends EventEmitter { constructor (opts) { + super() this.state = { network: 'loading' } this.opts = opts - this.listeners = [] this.configManager = new ConfigManager(opts) this.keyringController = new KeyringController({ configManager: this.configManager, @@ -62,6 +63,7 @@ module.exports = class MetamaskController { }) this.ethStore.on('update', this.sendUpdate.bind(this)) + this.keyringController.on('update', this.sendUpdate.bind(this)) } getState () { @@ -165,9 +167,7 @@ module.exports = class MetamaskController { sendUpdate () { this.getState() .then((state) => { - this.listeners.forEach((remote) => { - remote.sendUpdate(state) - }) + this.emit('update', state) }) } |