add debounce
This commit is contained in:
parent
b3e42cb427
commit
5adc4fd5d2
2 changed files with 22 additions and 23 deletions
|
|
@ -182,13 +182,6 @@ Identity.prototype.retrieveWalletFromStorage = function(walletId, opts, callback
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO (matiu): What is this supposed to do?
|
||||
*/
|
||||
Identity.isAvailable = function(email, opts, cb) {
|
||||
return cb();
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Wallet} wallet
|
||||
* @param {Function} cb
|
||||
|
|
@ -198,6 +191,7 @@ Identity.prototype.storeWallet = function(wallet, cb) {
|
|||
|
||||
var val = wallet.toObj();
|
||||
var key = wallet.getStorageKey();
|
||||
log.debug('Storing wallet:' + wallet.getName());
|
||||
|
||||
this.storage.setItem(key, val, function(err) {
|
||||
if (err) {
|
||||
|
|
@ -208,6 +202,18 @@ Identity.prototype.storeWallet = function(wallet, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Identity} identity
|
||||
* @param {Wallet} wallet
|
||||
* @param {Function} cb
|
||||
*/
|
||||
Identity.storeWalletDebounced = _.debounce(function(identity, wallet, cb) {
|
||||
identity.storeWallet(wallet,cb);
|
||||
}, 3000);
|
||||
|
||||
|
||||
|
||||
Identity.prototype.toObj = function() {
|
||||
return _.extend({
|
||||
walletIds: _.keys(this.wallets)
|
||||
|
|
@ -373,36 +379,29 @@ Identity.prototype.bindWallet = function(w) {
|
|||
log.debug('Binding wallet ' + w.getName());
|
||||
|
||||
w.on('txProposalsUpdated', function() {
|
||||
log.debug('<txProposalsUpdated>> Wallet' + w.getName());
|
||||
self.storeWallet(w);
|
||||
Identity.storeWalletDebounced(self, w);
|
||||
});
|
||||
w.on('newAddresses', function() {
|
||||
log.debug('<newAddresses> Wallet' + w.getName());
|
||||
self.storeWallet(w);
|
||||
Identity.storeWalletDebounced(self, w);
|
||||
});
|
||||
w.on('settingsUpdated', function() {
|
||||
log.debug('<newAddresses> Wallet' + w.getName());
|
||||
self.storeWallet(w);
|
||||
Identity.storeWalletDebounced(self, w);
|
||||
});
|
||||
w.on('txProposalEvent', function() {
|
||||
log.debug('<txProposalEvent> Wallet' + w.getName());
|
||||
self.storeWallet(w);
|
||||
Identity.storeWalletDebounced(self, w);
|
||||
});
|
||||
w.on('ready', function() {
|
||||
log.debug('<ready> Wallet' + w.getName());
|
||||
self.store({
|
||||
noWallets: true
|
||||
}, function() {
|
||||
self.storeWallet(w);
|
||||
Identity.storeWalletDebounced(self, w);
|
||||
});
|
||||
});
|
||||
w.on('addressBookUpdated', function() {
|
||||
log.debug('<addressBookUpdated> Wallet' + w.getName());
|
||||
self.storeWallet(w);
|
||||
Identity.storeWalletDebounced(self, w);
|
||||
});
|
||||
w.on('publicKeyRingUpdated', function() {
|
||||
log.debug('<publicKeyRingUpdated> Wallet' + w.getName());
|
||||
self.storeWallet(w);
|
||||
Identity.storeWalletDebounced(self, w);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue