rpc: add support for setting properties on RpcProxy

This commit is contained in:
Koushik Dutta
2022-10-28 10:15:58 -07:00
parent 5e4266c15f
commit fa6099f1d6
2 changed files with 30 additions and 1 deletions

View File

@@ -109,8 +109,14 @@ class RpcProxy implements PrimitiveProxyHandler<any> {
}
set(target: any, p: string | symbol, value: any, receiver: any): boolean {
if (p === RpcPeer.finalizerIdSymbol)
if (p === RpcPeer.finalizerIdSymbol) {
this.entry.finalizerId = value;
}
else {
this.proxyProps ||= {};
this.proxyProps[p] = value;
}
return true;
}

View File

@@ -0,0 +1,23 @@
import { RpcPeer } from "../src/rpc";
const p1 = new RpcPeer('p1', 'p2', message => {
p2.handleMessage(message);
});
const p2 = new RpcPeer('p2', 'p1', message => {
p1.handleMessage(message);
});
class Foo {
}
p1.params['thing'] = new Foo();
async function test() {
const foo = await p2.getParam('thing');
foo.bar = 3;
if (foo.bar !== 3)
throw new Error('proxy custom property set failed');
}
test();