Unsubscribe autocompile listener if disabled

This commit is contained in:
Alasdair Smith 2017-09-05 13:57:11 +01:00
parent cca7f55322
commit a9e94f6a6d

View file

@ -72,16 +72,26 @@ define [
$scope.pdf.view = 'errors' $scope.pdf.view = 'errors'
$scope.pdf.renderingError = true $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.autocompile_enabled = localStorage("autocompile_enabled:#{$scope.project_id}") or false
$scope.$watch "autocompile_enabled", (newValue, oldValue) -> $scope.$watch "autocompile_enabled", (newValue, oldValue) ->
if newValue? and oldValue != newValue if newValue? and oldValue != newValue
localStorage("autocompile_enabled:#{$scope.project_id}", newValue) localStorage("autocompile_enabled:#{$scope.project_id}", newValue)
toggleAutoCompile(newValue)
# TODO: toggle listener when setting changed? if window.user?.betaProgram and $scope.autocompile_enabled
ide.$scope.$on "ide:opAcknowledged", _.debounce(() -> toggleAutoCompile(true)
if (!ide.$scope.hasLintingError)
$scope.recompile()
, 3000) if window.user?.betaProgram and $scope.autocompile_enabled
# abort compile if syntax checks fail # abort compile if syntax checks fail
$scope.stop_on_validation_error = localStorage("stop_on_validation_error:#{$scope.project_id}") $scope.stop_on_validation_error = localStorage("stop_on_validation_error:#{$scope.project_id}")