type Subscriber < E > = ( event : E ) => any ; export class Signal < T = any > { private subscribers : Subscriber < T > [ ] = [ ] ; dispatch ( t ) { for ( const subscriber of this . subscribers ) { subscriber ( t ) ; } } subscribe ( subscriber ) { if ( this . subscribers . indexOf ( subscriber ) > - 1 ) { return ; } this . subscribers . push ( subscriber ) ; } unsubscribe ( subscriber ) { const index = this . subscribers . indexOf ( subscriber ) ; if ( index < 0 ) { return ; } this . subscribers . splice ( index , 1 ) ; } }