Skip to content

Commit

Permalink
Avoid calling bind on instances of RpcProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobMarshallPP committed May 21, 2024
1 parent 6f1c790 commit a7b2e6e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ export function unwrap<T extends object>(item: T): T {
}

export function passthroughGet(target: any, prop: string | symbol, thisArg?: any) {
const value = Reflect.get(unwrap(target), prop)
const unwrappedTarget = unwrap(target)
const value = Reflect.get(unwrappedTarget, prop)
if (typeof value === 'function') {
thisArg = thisArg || unwrap(target)
const bound = value.bind(thisArg)
return bound
if (value.constructor.name === 'RpcProperty') {
return (...args: unknown[]) => unwrappedTarget[prop](...args)
}
thisArg = thisArg || unwrappedTarget
return value.bind(thisArg)
} else {
return value
}
Expand Down

0 comments on commit a7b2e6e

Please sign in to comment.