debian-mirror-gitlab/app/assets/javascripts/lib/utils/rails_ujs.js
2021-01-30 21:13:32 +05:30

20 lines
542 B
JavaScript

import Rails from '@rails/ujs';
export const initRails = () => {
// eslint-disable-next-line no-underscore-dangle
if (!window._rails_loaded) {
Rails.start();
// Count XHR requests for tests. See spec/support/helpers/wait_for_requests.rb
window.pendingRailsUJSRequests = 0;
document.body.addEventListener('ajax:complete', () => {
window.pendingRailsUJSRequests -= 1;
});
document.body.addEventListener('ajax:beforeSend', () => {
window.pendingRailsUJSRequests += 1;
});
}
};
export { Rails };