Skip to content
This repository has been archived by the owner on Aug 23, 2018. It is now read-only.

Commit

Permalink
Provide root module name directly
Browse files Browse the repository at this point in the history
Possible fix for #50 and #61
  • Loading branch information
process-bot committed Dec 21, 2014
1 parent a4defe8 commit a5ce8bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
19 changes: 9 additions & 10 deletions backend/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ compile filePath =

toJson :: FilePath -> IO String
toJson filePath =
do result <- compile filePath
case result of
Right code ->
return (jsonReply "success" code)
do sourceCode <- readFile filePath
result <- compile filePath
case (,) <$> Compiler.parseDependencies sourceCode <*> result of
Right ((name, _deps), code) ->
return $
"{ \"name\": " ++ show (Module.nameToString name) ++
", \"code\": " ++ show code ++ " }"

Left err ->
return (jsonReply "error" err)


jsonReply :: String -> String -> String
jsonReply field value =
concat [ "{ ", show field, " : ", show value, " }" ]
return $
"{ \"error\": " ++ show err ++ " }"


-- TO HTML
Expand Down
28 changes: 14 additions & 14 deletions frontend/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

function debugFullscreenWithOptions(options) {

return function(module, moduleFile, swapState /* =undefined */) {
return function(elmModule, elmModuleFile, swapState /* =undefined */) {
var createdSocket = false;
var elmPermitSwaps = true;

var ELM_DEBUGGER_ID = "elmToolPanel";
var ELM_DARK_GREY = "#4A4A4A";
var ELM_LIGHT_GREY = "#E4E4E4";

var mainHandle = Elm.fullscreenDebugHooks(module, swapState);
var mainHandle = Elm.fullscreenDebugHooks(elmModule, swapState);
var debuggerHandle = initDebugger();
if (!options.externalSwap) {
initSocket();
Expand Down Expand Up @@ -159,8 +159,8 @@ function debugFullscreenWithOptions(options) {
function initSocket() {
createdSocket = true;
// "/todo.html" => "todo.elm"
moduleFile = moduleFile || window.location.pathname.substr(1).split(".")[0] + ".elm";
var socketLocation = "ws://" + window.location.host + "/socket?file=" + moduleFile;
elmModuleFile = elmModuleFile || window.location.pathname.substr(1).split(".")[0] + ".elm";
var socketLocation = "ws://" + window.location.host + "/socket?file=" + elmModuleFile;
var serverConnection = new WebSocket(socketLocation);
serverConnection.onmessage = function(event) {
if (elmPermitSwaps && debuggerHandle.ports) {
Expand All @@ -173,24 +173,24 @@ function debugFullscreenWithOptions(options) {
}

function swap(raw) {
var debuggerDiv = document.getElementById(ELM_DEBUGGER_ID);
var result = JSON.parse(raw);
var js = result.success;
var errorMessage = result.error;
var error = document.getElementById('ErrorMessage');
if (error) {
error.parentNode.removeChild(error);
}
if (js) {
window.eval(js);
var moduleStr = js.match(/(Elm\..+)\ =\ \1/)[1];
var module = window.eval(moduleStr);

var result = JSON.parse(raw);
var code = result.code;
var errorMessage = result.error;

if (code) {
window.eval(code);
var elmModule = window.eval('Elm.' + result.name);
if (mainHandle.debugger) {
var debuggerState = mainHandle.debugger.getSwapState();
mainHandle.debugger.dispose();
mainHandle.dispose();

mainHandle = Elm.fullscreenDebugHooks(module, debuggerState);
mainHandle = Elm.fullscreenDebugHooks(elmModule, debuggerState);

// The div that rejects events must be after Elm
var ignoringDiv = document.getElementById("elmEventIgnorer");
Expand All @@ -199,7 +199,7 @@ function debugFullscreenWithOptions(options) {
}
}
else {
mainHandle = mainHandle.swap(module);
mainHandle = mainHandle.swap(elmModule);
}
} else if (errorMessage) {
var errorNode = document.createElement("pre");
Expand Down

0 comments on commit a5ce8bd

Please sign in to comment.