import { Unsubscribe } from 'redux' ; import store , { RootState } from './' ; export interface Connectable { mapStateToProps ( state ) : any ; shouldUpdateProps ? ( state ) : boolean ; } type Constructor < T > = new ( ... args ) => T ; export function connect < T extends Constructor < Connectable > > ( superclass ) { class connected extends superclass { private unsubscribe : Unsubscribe ; connectedCallback ( ) { this . unsubscribe = store . subscribe ( ( ) => this . connect ( store . getState ( ) ) ) ; this . connect ( store . getState ( ) ) ; } disconnectedCallback ( ) { this . unsubscribe ( ) ; } shouldUpdateProps ( state ) { return true ; } connect ( state ) { if ( this . shouldUpdateProps ( state ) ) { this . setProperties ( this . mapStateToProps ( state ) ) ; } } setProperties ( val ) { Object . assign ( this , val ) ; } } return connected as T ; }