import * as React from "react"; import {ReactElement} from "react"; import {GlobalContext, GlobalContextContent} from "../react/global-context"; export interface StatefulBaseComponentConstructor extends React.ComponentClass

, React.ComponentLifecycle { new (props?: P, context?: any): StatefulBaseComponent; } /* do not use this, without special problem */ export abstract class StatefulBaseComponent extends React.Component implements GlobalContext { public readonly context: any; private static _bindingMethods; // not used any where public abstract state: S; constructor(props: P, context) { super(props, context); // console.log('constructor of', this.constructor.name); if (this.constructor.hasOwnProperty('_bindingMethods')) { this.constructor['_bindingMethods'].forEach((name) => { this[name] = this[name].bind(this); }); } this.afterConstruct(props, context); } afterConstruct(props: P, context: T) { } abstract render(): ReactElement|null; } export interface BaseComponentConstructor

extends React.ComponentClass

, React.ComponentLifecycle { new (props?: P, context?: any): BaseComponent

; } export interface ReactComponentConstructor

extends React.ComponentClass

, React.ComponentLifecycle { new (props?: P, context?: any): React.Component; } /** Redux base component */ export abstract class BaseComponent

extends StatefulBaseComponent implements GlobalContext { state: {}; } export function BindThis(target: StatefulBaseComponent, propertyKey: string|symbol, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor { if (descriptor === undefined) { throw new TypeError('@BindThis only allow to decorate method.'); } if (!target.constructor.hasOwnProperty('_bindingMethods')) { Object.defineProperty(target.constructor, '_bindingMethods', { configurable: true, enumerable: false, value: [], }); } target.constructor['_bindingMethods'].push(propertyKey); // console.log('BindThis of', target.constructor.name); // console.log(target.constructor['_bindingMethods']); return descriptor; }