1- import { type JSX , type ParentProps , createMemo , createRenderEffect , mergeProps } from "solid-js"
1+ import {
2+ type JSX ,
3+ type ParentProps ,
4+ createMemo ,
5+ createRenderEffect ,
6+ mergeProps ,
7+ splitProps ,
8+ } from "solid-js"
29import { Object3D } from "three"
310import { threeContext , useThree } from "./hooks.ts"
411import { manageSceneGraph , useProps } from "./props.ts"
5- import type { Instance , Props } from "./types.ts"
12+ import type { Constructor , Instance , Overwrite , Props } from "./types.ts"
613import { type InstanceFromConstructor } from "./types.ts"
714import { augment , autodispose , isConstructor , isInstance , withContext } from "./utils.ts"
815
@@ -58,9 +65,12 @@ export const Portal = (props: PortalProps) => {
5865/* */
5966/**********************************************************************************/
6067
61- type EntityProps < T extends object | ( new ( ...args : any [ ] ) => any ) > = Omit < Props < T > , "from" > & {
62- from : T
63- }
68+ type EntityProps < T extends object | Constructor < object > > = Overwrite <
69+ Props < T > ,
70+ {
71+ from : T
72+ }
73+ >
6474/**
6575 * Wraps a `ThreeElement` and allows it to be used as a JSX-component within a `solid-three` scene.
6676 *
@@ -70,13 +80,16 @@ type EntityProps<T extends object | (new (...args: any[]) => any)> = Omit<Props<
7080 * optional children, and a ref that provides access to the object instance.
7181 * @returns The Three.js object wrapped as a JSX element, allowing it to be used within Solid's component system.
7282 */
73- export function Entity < T extends object | ( new ( ...args : any [ ] ) => object ) > ( props : EntityProps < T > ) {
83+ export function Entity < T extends object | Constructor < object > > ( props : EntityProps < T > ) {
84+ const [ config , rest ] = splitProps ( props , [ "from" , "args" ] )
7485 const memo = createMemo ( ( ) => {
7586 return augment (
76- isConstructor ( props . from ) ? autodispose ( new props . from ( ...( props . args ?? [ ] ) ) ) : props . from ,
87+ isConstructor ( config . from )
88+ ? autodispose ( new config . from ( ...( config . args ?? [ ] ) ) )
89+ : config . from ,
7790 { props } ,
7891 ) as Instance < T >
7992 } )
80- useProps ( memo , props )
93+ useProps ( memo , rest )
8194 return memo as unknown as JSX . Element
8295}
0 commit comments