This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wrap = (obj, method) => { | |
const oldMethod = obj[method] | |
async function innerMethod(...args) { | |
const start = Date.now() | |
try { | |
const ret = await oldMethod.call(obj, ...args) | |
console.log(method, 'took', Date.now() - start, args[0]) | |
return ret | |
} catch (error) { | |
console.log(method, 'took', Date.now() - start) | |
throw error | |
} | |
} | |
Object.assign(obj, { [method]: innerMethod }) | |
} | |
function wrapMethods(obj) { | |
for (const method in obj) { | |
if (typeof obj[method] === 'function') { | |
wrap(obj, method) | |
} | |
} | |
} | |
wrapMethods(AsyncStorage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment