feat(HintCtrl): debounce message logging in UI

test-unit-sauce
Carlo s A. Guillen 10 years ago
parent fe231271b7
commit b94c14e5aa

@ -1,10 +1,10 @@
angular.module('ngHintUI',[]); angular.module('ngHintUI',[]);
angular.module('ngHintUI') angular.module('ngHintUI')
.controller('HintCtrl', ['$scope', .controller('HintCtrl', ['$scope', '$timeout',
function($scope){ function($scope, $timeout){
$scope.module, $scope.type, $scope.isEmpty = ''; $scope.module, $scope.type, $scope.isEmpty = '';
var currentPromises;
//message data will be an array sent from hint log to batarang to here //message data will be an array sent from hint log to batarang to here
// connect to background page // connect to background page
@ -20,7 +20,7 @@ angular.module('ngHintUI')
}; };
} }
$scope.messageData[result[0]][result[2]].push(result[1]); $scope.messageData[result[0]][result[2]].push(result[1]);
updateAll(); debounceUpdateAll();
}); });
port.onDisconnect.addListener(function (a) { port.onDisconnect.addListener(function (a) {
console.log(a); console.log(a);
@ -61,10 +61,14 @@ angular.module('ngHintUI')
} }
} }
$scope.messageData['All'] = all; $scope.messageData['All'] = all;
setTimeout(function() { $scope.$apply();
$scope.$apply(); }
console.log("called")
}, 3000); function debounceUpdateAll(){
$timeout.cancel(currentPromises);
currentPromises = $timeout(function() {
updateAll()
}.bind(this),1000)
} }
$scope.setModule = function(module) { $scope.setModule = function(module) {
$scope.module = module; $scope.module = module;