2 ms·
> Anything wrong with that? Well, don't events only bubble upwards? You need to know the exact element of it is not on a lower level in the DOM tree. Events w
by lelanthran 3y ago
> Anything wrong with that?
Well, don't events only bubble upwards? You need to know the exact element of it is not on a lower level in the DOM tree.
Events were too messy, so I wrote a small pub/sub message queue type of thing. Anyone anywhere in the DOM can subscribe to messages based on subject regexes.
Makes things a lot easier, especially when I added web components to wrap existing elements so that publishing and subscribing is done with attributes, not js.
- everybackdoor 3y agoYou can also fire events on pretty much any object, essentially creating a channel where the message bus queue is the vm event queue.
- lelanthran 3y ago> You can also fire events on pretty much any object, Only if you have a reference to the object. The reason I made up my own message queue pub/sub is because events required a lot of complexity in acquiring the correct reference to the correct object or subtree in the DOM. With pub/sub type message queue, any element can emit a message with subject "POST /getnetpage" and the function listening for (subscribed) POST messages emits a RESPONSE message when the response comes back. This lets a third element listen (subscribe) for a "RESPONSE FROM /getnextpage" subject message, and handle it. None of the 3 parties in the above need to have a reference to each other, nor do they even have to know about each other, and I can inject some nice observability tools because I can just add a subscriber for specific message types, which makes debugging a breeze.