From b382924cea2bcdc3dac96104e72833958577ef34 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Sat, 1 Oct 2022 12:12:32 -0700 Subject: [PATCH] feat: call components with `.call` to allow libs to provide class components with static `.call` methods Also formatted with prettier, some unformatted code got by in previous commits. Co-authored-by: Fabio Spampinato --- packages/solid/src/reactive/signal.ts | 2 +- packages/solid/src/render/component.ts | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/packages/solid/src/reactive/signal.ts b/packages/solid/src/reactive/signal.ts index cce7c8708..41ede402d 100644 --- a/packages/solid/src/reactive/signal.ts +++ b/packages/solid/src/reactive/signal.ts @@ -1031,7 +1031,7 @@ export function devComponent(Comp: (props: T) => JSX.Element, props: T) { () => untrack(() => { Object.assign(Comp, { [$DEVCOMP]: true }); - return Comp(props); + return Comp.call(Comp, props); }), undefined, true diff --git a/packages/solid/src/render/component.ts b/packages/solid/src/render/component.ts index c4b4458de..3a082cbbf 100644 --- a/packages/solid/src/render/component.ts +++ b/packages/solid/src/render/component.ts @@ -65,10 +65,7 @@ export type FlowComponent

= Component>; /** @deprecated: use `ParentProps` instead */ export type PropsWithChildren

= ParentProps

; -export type ValidComponent = - | keyof JSX.IntrinsicElements - | Component - | (string & {}); +export type ValidComponent = keyof JSX.IntrinsicElements | Component | (string & {}); /** * Takes the props of the passed component and returns its type @@ -77,13 +74,11 @@ export type ValidComponent = * ComponentProps // { mount?: Node; useShadow?: boolean; children: JSX.Element } * ComponentProps<'div'> // JSX.HTMLAttributes */ -export type ComponentProps = - T extends Component - ? P - : - T extends keyof JSX.IntrinsicElements - ? JSX.IntrinsicElements[T] - : Record; +export type ComponentProps = T extends Component + ? P + : T extends keyof JSX.IntrinsicElements + ? JSX.IntrinsicElements[T] + : Record; /** * Type of `props.ref`, for use in `Component` or `props` typing. @@ -99,7 +94,7 @@ export function createComponent(Comp: Component, props: T): JSX.Element { setHydrateContext(nextHydrateContext()); const r = "_SOLID_DEV_" ? devComponent(Comp, props || ({} as T)) - : untrack(() => Comp(props || ({} as T))); + : untrack(() => Comp.call(Comp, props || ({} as T))); setHydrateContext(c); return r; }