angular.module('ngHintUI', []).

controller('HintController', ['$scope', 'hintService', HintController]).

service('hintService', ['$rootScope', function($rootScope) {
  var onHintCallback,
      onRefreshCallback;

  this.onHint = function(cb) {
    onHintCallback = cb;
  };

  this.onRefresh = function(cb) {
    onRefreshCallback = cb;
  };

  var port = chrome.extension.connect();
  port.postMessage(chrome.devtools.inspectedWindow.tabId);
  port.onMessage.addListener(function(msg) {
    $rootScope.$apply(function () {
      if (msg === 'refresh') {
        onRefreshCallback();
      } else {
        var hint = JSON.parse(msg);
        onHintCallback(hint);
      }
    });
  });

  port.onDisconnect.addListener(function (a) {
    console.log(a);
  });

}]);

function HintController($scope, hintService) {

  resetMessageData();

  // TODO: rename this ?
  hintService.onRefresh(resetMessageData);

  function resetMessageData() {
    $scope.hints = [];
  }

  //Set the hint service to perform this action whenever
  //a new hint message is received.
  hintService.onHint(function(hint) {
    $scope.hints.push(hint);
  });
}

@@ -1,8 +1,23 @@
+'use strict';%0A%0A
 angular.
@@ -40,17 +40,18 @@
 ', %5B%5D).%0A
-%0A
+  
 controll
@@ -115,17 +115,18 @@
 ller%5D).%0A
-%0A
+  
 service(
@@ -155,24 +155,302 @@
 Scope', 
-function
+hintService%5D);%0A%0Afunction HintController($scope, hintService) %7B%0A  resetMessageData();%0A%0A  hintService.onRefresh(resetMessageData);%0A%0A  function resetMessageData() %7B%0A    $scope.hints = %5B%5D;%0A  %7D%0A%0A  hintService.onHint(function(hint) %7B%0A    $scope.hints.push(hint);%0A  %7D);%0A%7D%0A%0Afunction hintService
 ($rootSc
@@ -1055,380 +1055,7 @@
  %7D);
-%0A%0A%7D%5D);%0A%0Afunction HintController($scope, hintService) %7B%0A%0A  resetMessageData();%0A%0A  // TODO: rename this ?%0A  hintService.onRefresh(resetMessageData);%0A%0A  function resetMessageData() %7B%0A    $scope.hints = %5B%5D;%0A  %7D%0A%0A  //Set the hint service to perform this action whenever%0A  //a new hint message is received.%0A  hintService.onHint(function(hint) %7B%0A    $scope.hints.push(hint);%0A  %7D);
 %0A%7D%0A

move decls to top of file