Let's say we have an object:
const obj = { element }
and a Proxy with "asyncronous trap":
const proxy = new Proxy( obj, {
get: async function(obj, prop) {
if(prop === 'element') {
// wait until child element appears ( - just for example,
// in general this function returns delayed value)
const result = wait(obj[prop].querySelector('.child')); //promise
return await result;
}
}
})
I've tried code above but it doesn't work. It seems like Proxy doesn't recognize async get as a trap and don't intercept getter.
How to fix that? Or:
Is there another way to get 'delayed' value of object's property without mutation of original object?