From 1694094ea5ac8bca3c4d6a9e52db63667ebba9b3 Mon Sep 17 00:00:00 2001 From: Mantas Date: Fri, 11 Jan 2019 11:53:10 +0200 Subject: [PATCH] Allows to abort all ajax calls in the controller without releasing whole controller. --- .../controllers/_application_controller.coffee | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller.coffee b/app/assets/javascripts/app/controllers/_application_controller.coffee index 00bea44bd..eb08b8509 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.coffee @@ -74,9 +74,18 @@ class App.Controller extends Spine.Controller App.Event.unbindLevel(@controllerId) App.Delay.clearLevel(@controllerId) App.Interval.clearLevel(@controllerId) - if @ajaxCalls - for callId in @ajaxCalls - App.Ajax.abort(callId) + @abortAjaxCalls() + + abortAjaxCalls: => + if !@ajaxCalls + return + + idsToCancel = @ajaxCalls + + @ajaxCalls = [] + + for callId in idsToCancel + App.Ajax.abort(callId) release: -> # release custom bindings after it got removed from dom