Skip to content

Commit

Permalink
Avoid calling bind on instances of RpcProperty (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobMarshallPP authored May 28, 2024
1 parent 52100b5 commit 1b9b1c8
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 1b9b1c8

Please sign in to comment.