import { ElementMeta , EMIT_KEY , LISTEN_KEY } from '../decorator' ; import { attachDOM , attachShadow , attachStyle } from '../element' ; import { EventDispatcher } from '../event' ; export type OnInit = ( ) => void ; export interface StateChange { [ key ] : { previousValue : any ; newValue : any ; } ; } export type OnStateChange = ( change : StateChange , cb : ( change : StateChange ) => void ) => void ; export type SetState = ( property : string , model : any ) => void ; export type OnDestroy = ( ) => void ; export function bindListeners ( target ) { for ( const prop in target ) { if ( prop . includes ( LISTEN_KEY ) ) { this [ prop ] . onListener . call ( this ) ; } } } export function bindEmitters ( target ) { for ( const prop in target ) { if ( prop . includes ( EMIT_KEY ) ) { target [ prop ] . call ( target ) ; } } } export class StructuralElement extends HTMLElement { public emitter : EventDispatcher ; public elementMeta : ElementMeta ; constructor ( ) { super ( ) ; if ( this . bindEmitters ) { this . bindEmitters ( ) ; } if ( this . bindListeners ) { this . bindListeners ( ) ; } if ( this . onInit ) { this . onInit ( ) ; } } public onInit ? ( ) ; public bindEmitters ? ( ) ; public bindListeners ? ( ) ; public bindState ? ( ) ; public onUpdate ? ( ) ; public onDestroy ? ( ) ; } export class PseudoElement extends HTMLElement { public emitter : EventDispatcher ; public elementMeta : ElementMeta ; constructor ( ) { super ( ) ; attachDOM ( this ) ; attachStyle ( this ) ; if ( this . bindEmitters ) { this . bindEmitters ( ) ; } if ( this . bindListeners ) { this . bindListeners ( ) ; } if ( this . onInit ) { this . onInit ( ) ; } } public onInit ? ( ) ; public bindEmitters ? ( ) ; public bindListeners ? ( ) ; public bindState ? ( ) ; public setState ? ( property , model ) ; public onUpdate ? ( ) ; public onDestroy ? ( ) ; } export class CustomElement extends HTMLElement { public emitter : EventDispatcher ; public elementMeta : ElementMeta ; constructor ( ) { super ( ) ; attachShadow ( this , { mode : this . elementMeta . mode || 'open' } ) ; if ( this . bindEmitters ) { this . bindEmitters ( ) ; } if ( this . bindListeners ) { this . bindListeners ( ) ; } if ( this . onInit ) { this . onInit ( ) ; } } public onInit ? ( ) ; public bindEmitters ? ( ) ; public bindListeners ? ( ) ; public bindState ? ( ) ; public setState ? ( property , model ) ; public onUpdate ? ( ) ; public onDestroy ? ( ) ; }