UNPKG

@redpc/core

Version:

Remoted Procedure Call (RedPC) - A javascript RPC library written with TypeScript

27 lines (20 loc) 860 B
import { RpcMethod } from ".."; import { ProxyContext, ProxyContextMutator } from "../core/ProxyContext"; import { ProxyMethodConfig } from "../types"; const DefaultConfig: ProxyMethodConfig = { }; export function ProxyMethod(config?: ProxyMethodConfig): MethodDecorator { const props = config ?? DefaultConfig; return (target: Function | Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => { if (typeof target === 'function') { throw new RpcMethod(propertyKey.toString(), 'ProxyMethod must be applied to instance members only.'); } const ctx = ProxyContext.getContext(props.contextDomain) as ProxyContextMutator; return ctx.defineMember( props, target, propertyKey, descriptor ); } }