import React from "react" ; import { connect } from "react-redux" ; import { ConnectedComponentProps , Myth } from "./types" ; export class MythicComponent < MYTH extends Myth , PROPS = { } > extends React . PureComponent < ConnectedComponentProps < MYTH [ "name" ] , MYTH [ "props" ] , PROPS > > { constructor ( props ) { super ( props ) ; this . postConstructor ( ) ; } postConstructor ( ) { } ; } export const makeCreateConnectedComponent = < MYTH extends Myth > ( myth ) : typeof myth . createConnectedComponent => { return ( ( componentName , cls , makeState ) => { const component = connect ( makeState ?? null , ( dispatch ) => ( { [ myth . name ] : ( props ) => dispatch ( myth . create ( props ) ) , dispatch , } ) ) ( cls as any ) ; component . displayName = componentName ; return component ; } ) ; } ;