import { AnalyticsContext } from './AnalyticsContext' ; export type DispatchAnalytics < T > = ( eventName : string , context : AnalyticsContext ) => T ; export type AnalyticsExtender < T > = ( dispatcher : AnalyticsDispatcher < T > ) => AnalyticsDispatcher < T > ; export class AnalyticsDispatcher < T > { constructor ( private readonly dispatchAnalytics , readonly context = new AnalyticsContext ( ) ) { } dispatch ( eventName = '' , analyticsContext ? ) { const unionContext = this . context . union ( analyticsContext ) ; return this . dispatchAnalytics ( eventName , unionContext ) ; } extend ( ... extenders ) { return extenders . reduce ( ( acc , extender ) => extender ( acc ) , this ) ; } }