diff --git a/.gitignore b/.gitignore index fa2dbf2..25312c6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules/ dist/ .*.swp yarn-error.log +.vscode/ diff --git a/demo/demos/AllDemo.tsx b/demo/demos/AllDemo.tsx index ea5f3ad..cb5460e 100644 --- a/demo/demos/AllDemo.tsx +++ b/demo/demos/AllDemo.tsx @@ -4,14 +4,14 @@ import { ChainableComponent } from '../../src/ChainableComponent'; import Step from '../Step'; export const AllDemo = - ChainableComponent.all([ + ChainableComponent.allT( withState('string value'), withState(1), withState(2), withState(3), withState(5), withState(8) - ]) + ) .render(([a, b, c, d, e, f]) => (
+ {`hmm +`} ++ {FromNonStandardRenderPropDemo} +
( } /** - * Converts a Render Props Component into a function that can be used to build a ChainableComponent - * Represents the type of a non standard render prop - * @template P the props of the render prop component - * @template A the type of the parameter of the render function - * @template C the string of the key of the render function + * Extracts a parameter type from the render prop function. */ -type NonStandardRenderPropProps
= A & - { [K in C]: (a: P[K]) => React.ReactNode }; +type RenderPropContext
= P extends {[K in S]?: (a: infer U) => React.ReactNode} ? U : never; /** * Converts a Render Prop Component into a function that can be used to build a ChainableComponent @@ -249,13 +244,13 @@ type NonStandardRenderPropProps
= A & * A "non-standard" render prop is any render prop that does not use the 'children' prop as the render method. * @param Inner the render prop component */ -export function fromNonStandardRenderProp
( +export function fromNonStandardRenderProp
(
renderMethod: S,
- Inner: React.ComponentType ,
parameters?: Omit
-): ChainableComponent {
+): ChainableComponent (
Inner as any
);
return apply({
@@ -266,7 +261,7 @@ export function fromNonStandardRenderProp (
}
/**
- * Converts an apply function to a ChainableComponent
+ * Converts a render function to a ChainableComponent
* @param render
*/
export function fromRender(
@@ -308,6 +303,14 @@ export function fromRender(
type CC = ChainableComponent;
+
+type Unchained = A extends ChainableComponent