Prevent multiple unsubscribe calls for ActionCable

This commit is contained in:
Sebastian Serth
2023-09-06 00:00:27 +02:00
parent 4b90a2a3c5
commit 9f37034d0b
3 changed files with 13 additions and 3 deletions

View File

@ -42,6 +42,16 @@ $(document).on('turbolinks:load', function () {
send_changes(delta, active_file) {
const delta_with_user_id = {command: 'editor_change', current_user_id: current_user_id, active_file: active_file, delta: delta}
this.perform('send_changes', {delta_with_user_id: delta_with_user_id});
},
is_connected() {
return App.cable.subscriptions.findAll(App.synchronized_editor.identifier).length > 0
},
disconnect() {
if (this.is_connected()) {
this.unsubscribe();
}
}
});
}

View File

@ -1089,8 +1089,8 @@ var CodeOceanEditor = {
this.initializeDeadlines();
CodeOceanEditorTips.initializeEventHandlers();
window.addEventListener("turbolinks:before-render", App.synchronized_editor?.unsubscribe.bind(App.synchronized_editor));
window.addEventListener("beforeunload", App.synchronized_editor?.unsubscribe.bind(App.synchronized_editor));
window.addEventListener("turbolinks:before-render", App.synchronized_editor?.disconnect.bind(App.synchronized_editor));
window.addEventListener("beforeunload", App.synchronized_editor?.disconnect.bind(App.synchronized_editor));
window.addEventListener("turbolinks:before-render", this.autosaveIfChanged.bind(this));
window.addEventListener("beforeunload", this.autosaveIfChanged.bind(this));

View File

@ -204,7 +204,7 @@ CodeOceanEditorSubmissions = {
this.teardownEventHandlers();
this.createSubmission(button, null, function (response) {
if (response.redirect) {
App.synchronized_editor?.unsubscribe();
App.synchronized_editor?.disconnect();
this.autosaveIfChanged();
this.stopCode(event);
this.editors = [];