Skip to content

Commit

Permalink
Refactored the client code
Browse files Browse the repository at this point in the history
  • Loading branch information
rehno-lindeque committed May 21, 2012
1 parent 347ed2c commit 8404e8f
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 49 deletions.
1 change: 1 addition & 0 deletions client/src/core.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
var chompTestInspector = {};
10 changes: 10 additions & 0 deletions client/src/events.init.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,10 @@
var Init = {
messageService: function(){
state.ws = WebSocketService.create('/');
MessageService.attach(state.ws);
}
};

$(document).ready(function () {
Init.messageService();
});
5 changes: 5 additions & 0 deletions client/src/footer.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
// Export the applicatoin to a CommonJS module if exports is available
if (typeof(exports) !== "undefined" && exports !== null)
exports.module = chompTestInspector;
return chompTestInspector;
})();
6 changes: 6 additions & 0 deletions client/src/header.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* chomp-test-inspector-client.js - Test inspector for chomp (continuous integration, fully reactive)
* Copyright (C) Rehno Lindeque.
*/
var chompTestInspector = (function() {
"use strict";
21 changes: 20 additions & 1 deletion client/src/message.js
Original file line number Original file line Diff line number Diff line change
@@ -1 +1,20 @@
// TODO: message.js var
Message = adt('Acknowledge','Notify','ReloadFiles','PatchFile', 'ParseError'),

evalMessage = adt({
Acknowledge: function() { console.log("...previous message acknowledged"); },
Notify: function(notification) { console.log("...notification:", notification); },
ReloadFiles: function(files) {
console.log("...reload files: ", files);
},
PatchFile: function(filePath, patch) {
console.log("...apply patch to file: ", file);
console.log("...patch: ", patch);
},
ParseError: function(message) { console.error("...previous message this client sent could not be parsed: \n", message); },
_: function() { console.error("...(error) unknown message type `" + this._tag + "`" ); }
}),

sendMessage = function(ws, message) {
ws.send(adt.serialize(message));
};
16 changes: 16 additions & 0 deletions client/src/message.service.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,16 @@
var MessageService = {
// Attach to a websocket
attach: function (ws) {
if (ws == null)
return;
ws.onopen = function() {
//sendMessage(ws, "Message from client");
// TODO: do something meaningful here
};
ws.onmessage = function(event) {
console.log("Message received...");
console.log("...event: ", event);
evalMessage(adt.deserialize(event.data));
};
}
};
3 changes: 3 additions & 0 deletions client/src/state.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
var state = {
ws: null
};
45 changes: 0 additions & 45 deletions client/src/websocket-service.js

This file was deleted.

12 changes: 12 additions & 0 deletions client/src/websocket.service.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,12 @@
// Websocket service
var WebSocketService = {
// Create a websocket
create: function(path) {
var host = window.location.hostname;
if(host == '') host = 'localhost';
var uri = 'ws://' + host + ':8080' + path;
var Socket = 'MozWebSocket' in window ? MozWebSocket : WebSocket;
var ws = new Socket(uri);
return ws;
}
};
18 changes: 15 additions & 3 deletions src/TestInspectorPage.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,18 +39,30 @@ pageHtml = renderHtml [shamlet|
js = preEscapedLazyText $ LT.concat $ map (renderJavascriptUrl dummyRouter) jsFiles js = preEscapedLazyText $ LT.concat $ map (renderJavascriptUrl dummyRouter) jsFiles
css = preEscapedLazyText $ LT.concat $ map (renderCssUrl dummyRouter) cassiusFiles css = preEscapedLazyText $ LT.concat $ map (renderCssUrl dummyRouter) cassiusFiles
pageTitle = "Chomp" :: String pageTitle = "Chomp" :: String
pageSubTitle = "" :: String pageSubTitle = "A brave new LangLang compiler" :: String
test1Src = "" :: String test1Src = "" :: String


#if PRODUCTION #if PRODUCTION
jsFiles = [ jsFiles = [
$(jsFile "client/src/header.js"),
$(jsFile "client/src/core.js"),
$(jsFile "client/src/state.js"),
$(jsFile "client/src/websocket.service.js"),
$(jsFile "client/src/message.js"), $(jsFile "client/src/message.js"),
$(jsFile "client/src/websocket-service.js") $(jsFile "client/src/message.service.js"),
$(jsFile "client/src/events.init.js"),
$(jsFile "client/src/footer.js")
] ]
#else #else
jsFiles = [ jsFiles = [
$(jsFileReload "client/src/header.js"),
$(jsFileReload "client/src/core.js"),
$(jsFileReload "client/src/state.js"),
$(jsFileReload "client/src/websocket.service.js"),
$(jsFileReload "client/src/message.js"), $(jsFileReload "client/src/message.js"),
$(jsFileReload "client/src/websocket-service.js") $(jsFileReload "client/src/message.service.js"),
$(jsFileReload "client/src/events.init.js"),
$(jsFileReload "client/src/footer.js")
] ]
#endif #endif


Expand Down

0 comments on commit 8404e8f

Please sign in to comment.