arvgta / ajaxify

Ajaxify - The Ajax Plugin
https://4nf.org/
274 stars 124 forks source link

New Pronto events interface #234

Closed arvgta closed 1 year ago

arvgta commented 1 year ago

In a pure JS environment without jQuery, addEventListener() is used to register events instead of e.g. the old jQuery on(). One disadvantage of addEventListener() is that it does not deduplicate registration of pairs of event and event handler and therefore these can pile up in an unwanted way especially in an Ajax environment.

So, in order to at least deduplicate their registration, we've introduced a new convenience function for the user:

function _won(a, b, c = false) { if(c === false) c = {once: true}; setTimeout( () => window.addEventListener(a, b, c) ); };

...which can be called e.g. like this:

<script>_won('pronto.render', function(event) {
  console.log( event );
  });
</script>

For extensive documentation, please see the Events page on 4nf.org.