-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return proxy from
.value
properties (#795)
- Loading branch information
Showing
16 changed files
with
686 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
type Labelled, | ||
type ResolutionCtx, | ||
type SelfResolvable, | ||
isBufferUsage, | ||
} from '../types'; | ||
import { isAccessor, isDerived, isSlot } from './slot/slotTypes'; | ||
|
||
export const valueProxyHandler: ProxyHandler<SelfResolvable & Labelled> = { | ||
get(target, prop) { | ||
if (prop in target) { | ||
return Reflect.get(target, prop); | ||
} | ||
|
||
if (prop === '~providing') { | ||
return undefined; | ||
} | ||
|
||
return new Proxy( | ||
{ | ||
'~resolve': (ctx: ResolutionCtx) => | ||
`${ctx.resolve(target)}.${String(prop)}`, | ||
|
||
toString: () => | ||
`.value(...).${String(prop)}:${target.label ?? '<unnamed>'}`, | ||
}, | ||
valueProxyHandler, | ||
); | ||
}, | ||
}; | ||
|
||
export function unwrapProxy<T>(value: unknown): T { | ||
let unwrapped = value; | ||
|
||
while ( | ||
isSlot(unwrapped) || | ||
isDerived(unwrapped) || | ||
isAccessor(unwrapped) || | ||
isBufferUsage(unwrapped) | ||
) { | ||
unwrapped = unwrapped.value; | ||
} | ||
|
||
return unwrapped as T; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.