11import * as React from 'react' ;
22import { createElement as h } from 'react'
33import * as PropTypes from 'prop-types' ;
4- import { Plan , Xcomponent , XcomponentClass , ContextEngine , XREACT_ENGINE , Update , Actions } from './interfaces'
4+ import { Plan , Xcomponent , XcomponentClass , ContextEngine , XREACT_ENGINE , Update , Actions , Xprops } from './interfaces'
55import { streamOps , Stream , Subject } from './xs'
66
77export const CONTEXT_TYPE = {
@@ -18,7 +18,7 @@ export function extendXComponentClass<E extends Stream, I, S>(WrappedComponent:
1818 return class XNode extends WrappedComponent {
1919 static contextTypes = CONTEXT_TYPE
2020 static displayName = `X(${ getDisplayName ( WrappedComponent ) } )`
21- constructor ( props : S , context : ContextEngine < E , I , S > ) {
21+ constructor ( props : Xprops < I > , context : ContextEngine < E , I , S > ) {
2222 super ( props , context ) ;
2323 let engine = context [ XREACT_ENGINE ]
2424 let { actions, update$ } = main ( engine . intent$ , props )
@@ -28,12 +28,12 @@ export function extendXComponentClass<E extends Stream, I, S>(WrappedComponent:
2828 }
2929 }
3030}
31- export function genXComponentClass < E extends Stream , I , S > ( WrappedComponent : React . SFC < S > | React . ComponentClass < S > , main : Plan < E , I , S > , opts ?: any ) : XcomponentClass < E , I , S > {
31+ export function genXComponentClass < E extends Stream , I , S > ( WrappedComponent : React . ComponentType < S > , main : Plan < E , I , S > , opts ?: any ) : XcomponentClass < E , I , S > {
3232 return class XLeaf extends Xcomponent < E , I , S > {
3333 static contextTypes = CONTEXT_TYPE
3434 static displayName = `X(${ getDisplayName ( WrappedComponent ) } )`
3535 defaultKeys : ( keyof S ) [ ]
36- constructor ( props : any , context : ContextEngine < E , I , S > ) {
36+ constructor ( props : Xprops < I > , context : ContextEngine < E , I , S > ) {
3737 super ( props , context ) ;
3838 let engine = context [ XREACT_ENGINE ]
3939 let { actions, update$ } = main ( engine . intent$ , props )
@@ -43,14 +43,14 @@ export function genXComponentClass<E extends Stream, I, S>(WrappedComponent: Rea
4343 this . machine . actions = bindActions ( actions || { } , engine . intent$ , this )
4444
4545 this . defaultKeys = WrappedComponent . defaultProps ? ( < ( keyof S ) [ ] > Object . keys ( WrappedComponent . defaultProps ) ) : [ ] ;
46- this . state = Object . assign (
46+ this . setState ( Object . assign (
4747 { } ,
4848 WrappedComponent . defaultProps ,
49- pick ( this . defaultKeys , props )
50- ) ;
49+ < Pick < S , keyof S > > pick ( this . defaultKeys , props )
50+ ) ) ;
5151 }
5252 componentWillReceiveProps ( nextProps : I ) {
53- this . setState ( state => Object . assign ( { } , nextProps , pick ( this . defaultKeys , state ) ) ) ;
53+ this . setState ( ( state , props ) => Object . assign ( { } , nextProps , pick ( this . defaultKeys , state ) ) ) ;
5454 }
5555 componentDidMount ( ) {
5656 this . subscription = streamOps . subscribe (
@@ -109,7 +109,7 @@ export function genXComponentClass<E extends Stream, I, S>(WrappedComponent: Rea
109109 }
110110}
111111
112- function getDisplayName < E extends Stream , I , S > ( WrappedComponent : XcomponentClass < E , I , S > | React . SFC < S > | React . ComponentClass < S > ) {
112+ function getDisplayName < E extends Stream , I , S > ( WrappedComponent : React . ComponentType < S > ) {
113113 return WrappedComponent . displayName || WrappedComponent . name || 'X' ;
114114}
115115
@@ -137,7 +137,7 @@ function bindActions<E extends Stream, I, S>(actions: Actions<void>, intent$: Su
137137 return _actions ;
138138}
139139function pick < A > ( names : Array < keyof A > , obj : A ) {
140- let result = < Partial < A > > { } ;
140+ let result = < Pick < A , keyof A > > { } ;
141141 for ( let name of names ) {
142142 if ( obj [ name ] ) result [ name ] = obj [ name ] ;
143143 }
0 commit comments