News for hackers. Stuff that matters.
Re:A proposal to add signals to JavaScript by lelanthran on Sunday March 31, 2024 @03:57PM (#39887512)
> 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.

Re:A proposal to add signals to JavaScript by everybackdoor on Sunday March 31, 2024 @06:08PM (#39888512)
You can also fire events on pretty much any object, essentially creating a channel where the message bus queue is the vm event queue.
Re:A proposal to add signals to JavaScript by lelanthran on Monday April 01, 2024 @12:53AM (#39891032)
> 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.