gitlab-org--gitlab-foss/app/assets/javascripts/lib/utils/rails_ujs.js

21 lines
542 B
JavaScript
Raw Normal View History

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 };