import { EventEmitter2 } from "eventemitter2" ; import { COUNT_SELECTOR } from "coral-framework/constants" ; import { Decorator } from "./types" ; /**
 * withLiveCommentCount will listen to `commentCount` events
 * and update any comment counts managed by our `count.js` script.
 */ const withLiveCommentCount = ( eventEmitter ) : Decorator => ( ) => { eventEmitter . on ( "commentCount" , ( args ) => { const elements = document . querySelectorAll ( `${ COUNT_SELECTOR }[data-coral-url='${ args . storyURL }'], ${ COUNT_SELECTOR }[data-coral-id='${ args . storyID }']` ) ; elements . forEach ( ( element ) => { element . querySelectorAll ( ".coral-count-number" ) . forEach ( ( no ) => { no . innerHTML = args . number ; } ) ; element . querySelectorAll ( ".coral-count-text" ) . forEach ( ( no ) => { no . innerHTML = args . text ; } ) ; } ) ; } ) ; } ; export default withLiveCommentCount ;