Skip to content

Using Vanilla JS by default and added error handling

Compare
Choose a tag to compare
@nikolalsvk nikolalsvk released this 06 Oct 22:20
· 169 commits to master since this release

Vanilla JS

POSSIBLE BREAKING CHANGE

render_async now renders the usual, non-jQuery JavaScript code to fetch your AJAX requests and
show content on the page.

If you for some reason need jQuery part of render_async, you must configure render_async:

RenderAsync.configure do |config|
  config.jquery = true
end

Error handling

render_async 2.0.0 (finally) brings error handling to the gem.

You can pass in error_message argument to the render_async helper and have it show up
in the case of a failed AJAX request.

<%= render_async users_path,
                 error_message: '<p>Sorry, users loading went wrong :(</p>' %>

If your requests fails, users will see the "Sorry, users loading went wrong :(" message.

If that's not enough, you can pass in error_event_name which will trigger and event when
something bad happens to your request.

<%= render_asyc users_path, error_event_name: 'users-error-event' %>

Then, you can catch the event like this:

document.addEventListener('users-error-event', function() {
  // I'm on it
})

Events in IE

Event creation and dispatching should now work in IE 🎉