News for hackers. Stuff that matters.
Re:Show HN: CalDOM: An agnostic, reactive and minimalist Jav... by leipert on Monday July 19, 2021 @03:59PM (#27886682)
Looks interesting! Kudos on the well documented source, benchmark and website.

Are Caldom instances itself always synced with the DOM? e.g. If I create a Caldom instance for all ‘button’ and add an event handler for ‘click’. Now another piece of JavaScript adds a button to the page, will the event handler also trigger for that button or just the buttons when I first instantiated Caldom?

Re:Show HN: CalDOM: An agnostic, reactive and minimalist Jav... by dumindaxsb on Monday July 19, 2021 @10:45PM (#27889578)
Thank you. Worked really hard on the benchmark :)

No, it's not synced. When you use CalDOM without its reactive features, it's just a wrapper around the native DOM Element (similar to jQuery).

_("button").elem === document.querySelectorAll("button")[0]

Regarding capturing events of future elements: You can achieve this by setting an event listener to the parent.

Eg:

_("body").on("click", e => { if( e.target.matches("button") ) //Do something });