From a9e94f6a6d02040640a8e2c5ebc3d771e295b04a Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Tue, 5 Sep 2017 13:57:11 +0100 Subject: [PATCH] Unsubscribe autocompile listener if disabled --- .../ide/pdf/controllers/PdfController.coffee | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee b/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee index 3406f36f51..3c9915cdfa 100644 --- a/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee +++ b/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee @@ -72,16 +72,26 @@ define [ $scope.pdf.view = 'errors' $scope.pdf.renderingError = true + triggerAutoCompile = () -> + if (!ide.$scope.hasLintingError) + $scope.recompile() + + autoCompileListener = null + toggleAutoCompile = (enabling) -> + if enabling + autoCompileListener = ide.$scope.$on "ide:opAcknowledged", _.debounce(triggerAutoCompile, 3000) + else + autoCompileListener() if autoCompileListener + autoCompileListener = null + $scope.autocompile_enabled = localStorage("autocompile_enabled:#{$scope.project_id}") or false $scope.$watch "autocompile_enabled", (newValue, oldValue) -> if newValue? and oldValue != newValue localStorage("autocompile_enabled:#{$scope.project_id}", newValue) + toggleAutoCompile(newValue) -# TODO: toggle listener when setting changed? - ide.$scope.$on "ide:opAcknowledged", _.debounce(() -> - if (!ide.$scope.hasLintingError) - $scope.recompile() - , 3000) if window.user?.betaProgram and $scope.autocompile_enabled + if window.user?.betaProgram and $scope.autocompile_enabled + toggleAutoCompile(true) # abort compile if syntax checks fail $scope.stop_on_validation_error = localStorage("stop_on_validation_error:#{$scope.project_id}")