11import { WebCellProps , WebCellClass , VNode , patch } from 'web-cell' ;
22import { autorun } from 'mobx' ;
33
4- export type FunctionComponent = ( props ?: WebCellProps ) => VNode ;
4+ export type FunctionComponent < P extends WebCellProps = WebCellProps > = (
5+ props ?: P
6+ ) => VNode ;
57
6- function wrapFunction ( func : FunctionComponent ) {
7- return function ( props ?: WebCellProps ) {
8+ function wrapFunction < P > ( func : FunctionComponent < P > ) {
9+ return function ( props ?: P ) {
810 var vTree : VNode ;
911
1012 autorun (
@@ -14,17 +16,19 @@ function wrapFunction(func: FunctionComponent) {
1416 } ;
1517}
1618
17- function wrapClass ( Class : WebCellClass ) {
19+ function wrapClass < P , S > ( Class : WebCellClass < P , S > ) {
1820 const { update } = Class . prototype ;
1921
2022 Class . prototype . update = function ( ) {
2123 autorun ( ( ) => update . call ( this ) ) ;
2224 } ;
2325}
2426
25- export function observer ( Class : FunctionComponent | WebCellClass ) : any {
27+ export function observer < P , S > (
28+ Class : FunctionComponent < P > | WebCellClass < P , S >
29+ ) : any {
2630 if ( Object . getPrototypeOf ( Class ) === Function . prototype )
27- return wrapFunction ( Class as FunctionComponent ) ;
31+ return wrapFunction ( Class as FunctionComponent < P > ) ;
2832
29- wrapClass ( Class as WebCellClass ) ;
33+ wrapClass ( Class as WebCellClass < P , S > ) ;
3034}
0 commit comments