import { Observable , fromEvent } from 'rxjs' ; import { scan , startWith } from 'rxjs/operators' ; import type { ExpressionFunctionDefinition } from 'src/plugins/expressions' ; export interface CountEventArguments { event : string ; } export const countEvent = { name : 'countEvent' , type : 'number' , help : 'Subscribes for an event and counts a number of triggers.' , args : { event : { aliases : [ '_' ] , types : [ 'string' ] , help : 'The event name.' , required : true , } , } , fn ( input , { event } ) { return fromEvent ( window , event ) . pipe ( scan ( ( count ) => count + 1 , 1 ) , startWith ( 1 ) ) ; } , } ;