import {IStateSelector} from './IStateSelector' import {connect, Omit} from 'react-redux' import {Dispatch} from 'redux' import {ComponentType} from 'react' // https://stackoverflow.com/questions/54277411 export abstract class Connector { abstract connect( getLocalState: IStateSelector, ): ComponentType protected wrap< State, LocalState, StateProps, DispatchProps, Props >( getLocalState: IStateSelector, mapStateToProps: (state: LocalState) => StateProps, mapDispatchToProps: (dispatch: Dispatch) => DispatchProps, Component: React.ComponentType, ): ComponentType< Omit > { return connect( (state: State) => { const l = getLocalState(state) return mapStateToProps(l) }, mapDispatchToProps, )(Component as any) as any } }