11import * as React from 'react' ;
2- import PropTypes from 'prop-types' ;
2+ import { PropTypes } from 'prop-types' ;
33import initHistory , { Traveler } from './history' ;
44import { from , Stream , Subscription } from 'most' ;
55import { Engine , EngineSubject } from './engine/most' ;
@@ -10,30 +10,37 @@ const CONTEXT_TYPE = {
1010 [ REACT_MOST_ENGINE ] : PropTypes . object
1111} ;
1212
13- interface Actions < T > {
13+ export interface Actions < T > {
1414 [ propName : string ] : ( ...v : any [ ] ) => T
1515}
1616
17- interface Plan < I , S > {
18- ( intent : EngineSubject < I > , props ?: { } ) : Process < I , S >
17+ export interface Plan < I , S > {
18+ ( intent : EngineSubject < I > , props ?: { } ) : Process < I , S >
1919}
20- interface Update < S > {
20+ export interface Update < S > {
2121 ( current : S ) : S
2222}
23- interface Process < I , S > {
23+ export interface Process < I , S > {
2424 actions : Actions < I > ,
2525 updates : Stream < Update < S > >
2626}
2727
28- interface ConnectProps < I > {
28+ export interface ConnectProps < I > {
2929 actions : Actions < I >
3030}
3131const h = React . createElement ;
32- function connect < I , S > ( main : Plan < I , S > , opts = { history : false } ) {
32+ export class Connect < I , S > extends React . PureComponent < ConnectProps < I > , S > {
33+ actions : Actions < I >
34+ updates : Stream < Update < S > >
35+ }
36+ export interface ConnectClass < I , S > {
37+ new ( props ?: ConnectProps < I > , context ?: any ) : Connect < I , S > ;
38+ }
39+ export function connect < I , S > ( main : Plan < I , S > , opts = { history : false } ) : ( WrappedComponent : React . ComponentClass < any > ) => ConnectClass < I , S > {
3340 return function ( WrappedComponent : React . ComponentClass < any > ) {
3441 let connectDisplayName = `Connect(${ getDisplayName ( WrappedComponent ) } )` ;
3542 if ( WrappedComponent . contextTypes === CONTEXT_TYPE ) {
36- return class ConnectNode extends React . PureComponent < ConnectProps < I > , any > {
43+ return class ConnectNode extends Connect < I , S > {
3744 actions : Actions < I >
3845 updates : Stream < Update < S > >
3946 static contextTypes = CONTEXT_TYPE
@@ -55,7 +62,7 @@ function connect<I,S>(main: Plan<I,S>, opts = { history: false }) {
5562 }
5663 }
5764 } else {
58- return class ConnectLeaf extends React . PureComponent < ConnectProps < I > , S > {
65+ return class ConnectLeaf extends Connect < I , S > {
5966 actions : Actions < I >
6067 updates : Stream < Update < S > >
6168 traveler : Traveler < S >
@@ -71,7 +78,7 @@ function connect<I,S>(main: Plan<I,S>, opts = { history: false }) {
7178 }
7279
7380 let { actions, updates } = main ( context [ REACT_MOST_ENGINE ] . engine . intentStream , props )
74- this . updates = props . updates ? updates . merge ( props . updates ) : updates
81+ this . updates = props . updates ? updates . merge ( props . updates ) : updates
7582 this . actions = Object . assign ( { } , actions , props . actions ) ;
7683 let defaultKey = Object . keys ( WrappedComponent . defaultProps ) ;
7784 this . state = Object . assign (
0 commit comments