GoogleChromeLabs / GoogleChromeLabs/comlink

Feature request: Automatic proxy of arguments

Open
#662 4 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.