import * as React from "react"; import { CreateContextFeed } from "./ContextFeed"; import { ProtocolConfig } from "./ProtocolConfig"; export { ProtocolConfig }; interface Props { config: Config } export abstract class Protocol< Config extends ProtocolConfig > extends React.Component> { // Complete any asynchronous initialization work needed by the ProtocolConfig protected async initialize() { } protected static _ConfigContext: React.Context<{}>; // This trick allows us to access the static objects // defined in the derived class. See this code sample: // https://github.com/Microsoft/TypeScript/issues/5989#issuecomment-163066313 // @ts-ignore: This should always be true "constructor": typeof Protocol; public render() { const ConfigProvider = this.constructor._ConfigContext.Provider as any; const { config, children } = this.props; return ( {children} ) } public async componentDidMount() { await this.initialize(); this.forceUpdate(); } }