-
Notifications
You must be signed in to change notification settings - Fork 421
Open
Description
Out of curiosity, why doesn't comlink automatically proxy callbacks out of the box or at least give an opt-in for that?
I have been able to achieve it in the following way…
function $<T>(w: Worker): Remote<T> {
const remote = comlinkWrap<T>(w);
return new Proxy<Remote<T>>(remote, {
get(target, prop, receiver) {
if (typeof target[prop] === 'function') {
return new Proxy(target[prop], {
apply(target, thisArg, argArray) {
// Proxy functions in the argument list as well
const proxiedArgs = argArray.map(arg => (typeof arg === 'function' ? comlinkProxy(arg) : arg));
return Reflect.apply(target, thisArg, proxiedArgs);
},
});
}
return Reflect.get(target, prop, receiver);
},
});
}Am I missing something important here?
Metadata
Metadata
Assignees
Labels
No labels