import { EventListener , Subscribable , Triggerable } from "event/Event" ; export class SyncEvent < T > implements Subscribable < T > , Triggerable < T > { private readonly listeners : Map < EventListener < T > , EventListener < T > > = new Map ( ) ; public dispatch ( data ) { this . listeners . forEach ( listener => { listener ( data ) ; } ) ; return this ; } public dispose ( ) { this . listeners . clear ( ) ; } public subscribe ( listener ) { this . listeners . set ( listener , listener ) ; return this ; } public unsubscribe ( listener ) { this . listeners . delete ( listener ) ; return this ; } public once ( listener ) { this . listeners . set ( listener , data => { listener ( data ) ; this . unsubscribe ( listener ) ; } ) ; return this ; } public listener ( ) { return ( target , propertyKey , descriptor ) => { const listener = descriptor . value ; this . subscribe ( listener as EventListener < T > ) ; return descriptor ; } ; } }