Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Pronto events interface #234

Closed
arvgta opened this issue Oct 16, 2022 · 0 comments
Closed

New Pronto events interface #234

arvgta opened this issue Oct 16, 2022 · 0 comments

Comments

@arvgta
Copy link
Owner

arvgta commented Oct 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant