Permalink
Browse files

Refactored the client code

  • Loading branch information...
1 parent 347ed2c commit 8404e8f9b7e6acd21db2633906aedc2a742a6229 @rehno-lindeque rehno-lindeque committed May 21, 2012
View
1 client/src/core.js
@@ -0,0 +1 @@
+ var chompTestInspector = {};
View
10 client/src/events.init.js
@@ -0,0 +1,10 @@
+ var Init = {
+ messageService: function(){
+ state.ws = WebSocketService.create('/');
+ MessageService.attach(state.ws);
+ }
+ };
+
+ $(document).ready(function () {
+ Init.messageService();
+ });
View
5 client/src/footer.js
@@ -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;
+})();
View
6 client/src/header.js
@@ -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";
View
21 client/src/message.js
@@ -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));
+ };
View
16 client/src/message.service.js
@@ -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));
+ };
+ }
+ };
View
3 client/src/state.js
@@ -0,0 +1,3 @@
+ var state = {
+ ws: null
+ };
View
45 client/src/websocket-service.js
@@ -1,45 +0,0 @@
-// Websocket service
-(function(){
- 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));
- },
-
- createWebSocket = function(path) {
- var host = window.location.hostname;
- if(host == '') host = 'localhost';
- var uri = 'ws://' + host + ':8080' + path;
- var Socket = 'MozWebSocket' in window ? MozWebSocket : WebSocket;
- return new Socket(uri);
- };
-
- $(document).ready(function () {
- var ws = createWebSocket('/');
-
- 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));
- };
- });
-})();
View
12 client/src/websocket.service.js
@@ -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;
+ }
+ };
View
18 src/TestInspectorPage.hs
@@ -39,18 +39,30 @@ pageHtml = renderHtml [shamlet|
js = preEscapedLazyText $ LT.concat $ map (renderJavascriptUrl dummyRouter) jsFiles
css = preEscapedLazyText $ LT.concat $ map (renderCssUrl dummyRouter) cassiusFiles
pageTitle = "Chomp" :: String
- pageSubTitle = "" :: String
+ pageSubTitle = "A brave new LangLang compiler" :: String
test1Src = "" :: String
#if PRODUCTION
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/websocket-service.js")
+ $(jsFile "client/src/message.service.js"),
+ $(jsFile "client/src/events.init.js"),
+ $(jsFile "client/src/footer.js")
]
#else
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/websocket-service.js")
+ $(jsFileReload "client/src/message.service.js"),
+ $(jsFileReload "client/src/events.init.js"),
+ $(jsFileReload "client/src/footer.js")
]
#endif

0 comments on commit 8404e8f

Please sign in to comment.