nikolalsvk / render_async

render_async lets you include pages asynchronously with AJAX
https://rubygems.org/gems/render_async/
MIT License
1.08k stars 75 forks source link

Add generic "load" and "error" events #103

Closed lipsumar closed 4 years ago

lipsumar commented 4 years ago

This PR adds 2 generic javascript events: render_async_load and render_async_error.

Use case In a project with a lot of render_async, you might want to apply javascript to all content, even content loaded asynchronously. Adding a custom event name for every use of render_async is not practical, so this generic event allows to handle all render_async in 1 event handler.

nikolalsvk commented 4 years ago

Hey, @lipsumar! Thank you for this contribution!

The code looks great to me, nice job. I just have one concern - what if someone doesn't want to have events fired by default? Would it make sense to have this turned off by default?

I would add an option inside configuration so folks can enable this, WDYT?

lipsumar commented 4 years ago

Thanks for the fast review !

To answer your question: events in JavaScript fire all the time, if you don’t listen to them they’re a bit like the tree falling while no one is around :)

If one is interested in getting an event only for one specific render_async, one could use the « event_name » option or filter using event.container

nikolalsvk commented 4 years ago

This is released in 2.1.5 version 🎉

Thanks for all the help!