Hello Siya,
You will find inspiration from Firebase component, FirebaseReciever web block. (This is using jquery)
One approach to achieve what you need using javascript is explained below
Step 1: Create a web block with Events you wish to trigger
Step 2: Implement a custom listener with a getter & setter on a javascript object.
Step 3: In the Initialize() of the web block register for a callback
Step 4: Set the value from your javascript when you wish to trigger the event.
Step 5: When the callback is fired in the web block, hook it to an action in the web block that can trigger the event.
Check this link on how to implement the custom listener.
Hope this helps.