diff --git a/hint.html b/hint.html
index 9d57993..04f0d6f 100644
--- a/hint.html
+++ b/hint.html
@@ -5,7 +5,9 @@
-
+
+
+
diff --git a/hintApp.js b/hintApp.js
new file mode 100644
index 0000000..85cc419
--- /dev/null
+++ b/hintApp.js
@@ -0,0 +1 @@
+angular.module('ngHintUI',[]);
diff --git a/HintCtrl.js b/hintCtrl.js
similarity index 85%
rename from HintCtrl.js
rename to hintCtrl.js
index 8cb8365..3599129 100644
--- a/HintCtrl.js
+++ b/hintCtrl.js
@@ -1,21 +1,7 @@
-angular.module('ngHintUI',[]);
-
angular.module('ngHintUI')
- .controller('HintCtrl', ['$scope', '$timeout',
- function($scope, $timeout){
- $scope.module, $scope.type, $scope.suppressedMessages = {}, $scope.suppressedMessagesLength = 0;
- var currentPromises;
- //message data will be an array sent from hint log to batarang to here
-
- // connect to background page
- var port = chrome.extension.connect();
- port.postMessage(chrome.devtools.inspectedWindow.tabId);
- port.onMessage.addListener(function(msg) {
- if(msg == 'refresh') {
- $scope.messageData = {};
- return;
- }
-
+ .controller('HintCtrl', ['$scope', '$timeout', 'hintService',
+ function($scope, $timeout, hintService) {
+ hintService.setHintFunction(function(msg) {
$scope.messageData = $scope.messageData || {};
var result = msg.split('##'); //[modName, message, messageType]
if(!$scope.messageData[result[0]]) {
@@ -28,10 +14,10 @@ angular.module('ngHintUI')
$scope.messageData[result[0]][result[2]].push(result[1]);
debounceUpdateAll();
});
- port.onDisconnect.addListener(function (a) {
- console.log(a);
- });
+ $scope.module, $scope.type, $scope.suppressedMessages = {}, $scope.suppressedMessagesLength = 0;
+ var currentPromises;
+ //message data will be an array sent from hint log to batarang to here
$scope.labels = ['All Messages', 'Error Messages', 'Warning Messages', 'Suggestion Messages'];
function updateAll(){
diff --git a/hintService.js b/hintService.js
new file mode 100644
index 0000000..97356f6
--- /dev/null
+++ b/hintService.js
@@ -0,0 +1,26 @@
+angular.module('ngHintUI').
+ service('hintService', function() {
+ var onHintFunction;
+
+ this.setHintFunction = function(hintFunction) {
+ onHintFunction = hintFunction;
+ }
+
+ this.getHintFunction = function() {
+ return onHintFunction;
+ }
+
+ var port = chrome.extension.connect();
+ port.postMessage(chrome.devtools.inspectedWindow.tabId);
+ port.onMessage.addListener(function(msg) {
+ if(msg == 'refresh') {
+ this.messageData = [];
+ return;
+ }
+ onHintFunction(msg);
+ });
+
+ port.onDisconnect.addListener(function (a) {
+ console.log(a);
+ });
+});
\ No newline at end of file
diff --git a/hintService_test.js b/hintService_test.js
new file mode 100644
index 0000000..daf33b3
--- /dev/null
+++ b/hintService_test.js
@@ -0,0 +1,40 @@
+describe('hintService', function() {
+ var hintService;
+
+ beforeEach(module('ngHintUI'));
+ beforeEach(inject(function(_hintService_) {
+ hintService = _hintService_;
+ }));
+
+ var messageFunction = {
+ addListener: jasmine.createSpy('messageFunction')
+ }
+ var postMessageFunction = jasmine.createSpy('postMessageFunction');
+ var onDisconnectFunction = {
+ addListener: jasmine.createSpy('onDisconnect')
+ }
+ chrome = {
+ extension: {
+ connect: function() {
+ return {
+ onMessage: messageFunction,
+ postMessage: postMessageFunction,
+ onDisconnect: onDisconnectFunction
+ };
+ }
+ },
+ devtools: {
+ inspectedWindow: {
+ tabId: 1
+ }
+ }
+ };
+
+ it('should set the function to be executed for each hint', function() {
+ var onHintFunction = function() {
+ console.log('Do this when passed a hint.');
+ };
+ hintService.setHintFunction(onHintFunction);
+ expect(hintService.getHintFunction()).toEqual(onHintFunction);
+ });
+});