import { DynamicActionsState } from '../../common' ; import { getMetricKey } from './get_metric_key' ; export const dynamicActionsCollector = ( state , currentStats ) : Record < string , number > => { const stats = { ... currentStats } ; const countMetricKey = getMetricKey ( 'count' ) ; stats [ countMetricKey ] = state . events . length + ( stats [ countMetricKey ] || 0 ) ; for ( const event of state . events ) { const factoryId = event . action . factoryId ; const actionCountMetric = getMetricKey ( `actions.${ factoryId }.count` ) ; stats [ actionCountMetric ] = 1 + ( stats [ actionCountMetric ] || 0 ) ; for ( const trigger of event . triggers ) { const triggerCountMetric = getMetricKey ( `triggers.${ trigger }.count` ) ; const actionXTriggerCountMetric = getMetricKey ( `action_triggers.${ factoryId }_${ trigger }.count` ) ; stats [ triggerCountMetric ] = 1 + ( stats [ triggerCountMetric ] || 0 ) ; stats [ actionXTriggerCountMetric ] = 1 + ( stats [ actionXTriggerCountMetric ] || 0 ) ; } } return stats ; } ;