GoogleChromeLabs / GoogleChromeLabs/comlink
Feature request: Automatic proxy of arguments
- Dominant language
- TypeScript
- Stars
- 12.8k
- Forks
- 435
- PR merge metrics
- No merged PRs in 30d
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…
```typescript
function $(w: Worker): Remote {
const remote = comlinkWrap(w);
return new Proxy>(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?
Contributor guide
Assessment
This issue has not been assessed yet.