Prevent multiple unsubscribe calls for ActionCable
This commit is contained in:
@ -42,6 +42,16 @@ $(document).on('turbolinks:load', function () {
|
|||||||
send_changes(delta, active_file) {
|
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}
|
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});
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1089,8 +1089,8 @@ var CodeOceanEditor = {
|
|||||||
this.initializeDeadlines();
|
this.initializeDeadlines();
|
||||||
CodeOceanEditorTips.initializeEventHandlers();
|
CodeOceanEditorTips.initializeEventHandlers();
|
||||||
|
|
||||||
window.addEventListener("turbolinks:before-render", 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?.unsubscribe.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("turbolinks:before-render", this.autosaveIfChanged.bind(this));
|
||||||
window.addEventListener("beforeunload", this.autosaveIfChanged.bind(this));
|
window.addEventListener("beforeunload", this.autosaveIfChanged.bind(this));
|
||||||
|
@ -204,7 +204,7 @@ CodeOceanEditorSubmissions = {
|
|||||||
this.teardownEventHandlers();
|
this.teardownEventHandlers();
|
||||||
this.createSubmission(button, null, function (response) {
|
this.createSubmission(button, null, function (response) {
|
||||||
if (response.redirect) {
|
if (response.redirect) {
|
||||||
App.synchronized_editor?.unsubscribe();
|
App.synchronized_editor?.disconnect();
|
||||||
this.autosaveIfChanged();
|
this.autosaveIfChanged();
|
||||||
this.stopCode(event);
|
this.stopCode(event);
|
||||||
this.editors = [];
|
this.editors = [];
|
||||||
|
Reference in New Issue
Block a user