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

Toggle: unbind event after partial fetched #94

Closed fffx closed 4 years ago

fffx commented 5 years ago

Shouldn't we unbind the Event after partial fetched? I notice that the event still triggered and fetch the partial every time after the partial already be rendered.

In jquery we can achieve this by use namespace event, and in pure js we can use removeEventListener

I would like make PR if this is a bug?

nikolalsvk commented 5 years ago

I am not sure about unbinding the event, idea is to possibly toggle render_async as many times as you want. For example, maybe users want to do something like this:

<a href='#' id='reload-comments'>Reload</a>
<%= render_async comments_path, toggle: { selector: '#reload-comments', event: :click } %>

But, we can add a possibility to unbind the event if it's a problem for some folks. Leave 👍 if you'd like to see this in render_async

Tab10id commented 5 years ago

For example, maybe users want to do something like this

I want it. I'd love to render some widget by additional request and rerender it when some event happened. For now I can achive this only by hack with container_id (I render wrapper with that id on renderred partial).

nikolalsvk commented 5 years ago

This is solved in https://github.com/renderedtext/render_async/pull/96 and released in 2.1.4 version https://github.com/renderedtext/render_async/releases/tag/2.1.4