When I need to signal something across my application, I use events: window.dispatchEvent(new Event('counterChange')); And every part of the application that wants to react to it can subscribe via window.addEventListener('counterChange', () => { ... do something ... }); Anything wrong with that?
Welcome to Node.js v21.6.2. Type ".help" for more information. > window.dispatchEvent(new Event('counterChange')) Uncaught ReferenceError: window is not defined
$ node
Welcome to Node.js v20.6.1.
Type ".help" for more information.
> const target = new EventTarget()
undefined
> target.dispatchEvent(new Event("counterChange"))
true