A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/app/scripts/lib/ensnare.js

25 lines
622 B

module.exports = ensnare
// creates a proxy object that calls cb everytime the obj's properties/fns are accessed
9 years ago
function ensnare (obj, cb) {
var proxy = {}
9 years ago
Object.keys(obj).forEach(function (key) {
var val = obj[key]
switch (typeof val) {
case 'function':
9 years ago
proxy[key] = function () {
cb()
val.apply(obj, arguments)
}
return
default:
Object.defineProperty(proxy, key, {
9 years ago
get: function () { cb(); return obj[key] },
set: function (val) { cb(); obj[key] = val; return val },
})
return
}
})
return proxy
}