6Elm.debuggerInit = function(module) {
8 make: function(runtime) {
9 Elm.Debugger = debuggerInit(module, runtime);
10 return Elm.Debugger.moduleRetValue;
15function debuggerInit(module, runtime) {
17 var programPaused = false;
20 var recordedEvents = [];
23 var initialProgramState = {
28 function wrapNotify(id, v) {
29 var timestep = Date.now();
32 // ignore notify because we are stepping
35 runtime.notify(id, v, timestep);
36 recordEvent(id, v, timestep);
40 function wrapRunDelayed(func, delayMs) {
41 return safeSetTimeout(func, delayMs);
44 function safeSetTimeout(func, delayMs) {
45 var timerId = setTimeout(func, delayMs);
46 asyncTimers.push({ func:func, delayMs:delayMs, timerId:timerId });
50 function recordEvent(id, v, timestep) {
51 recordedEvents.push({ id:id, value:v, timestep:timestep });
54 function resetProgram() {
56 restoreNodeValues(allNodes, initialProgramState.nodeValues);
60 function restartProgram() {
63 initialProgramState.asyncTimers.forEach(function(timer) {
64 var func = timer.func;
69 function stepTo(index) {
75 if (index < 0 || index >= recordedEvents.length) {
76 throw "Index out of bounds: " + index;
79 if (index < eventCounter) {
84 assert(index >= eventCounter, "index must be bad");
85 while (eventCounter < index) {
86 var nextEvent = recordedEvents[eventCounter];
87 runtime.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);
91 assert(eventCounter == index, "while loop didnt' work");
94 function getMaxSteps() {
95 return recordedEvents.length - 1;
98 function clearAsyncEvents() {
99 asyncTimers.forEach(function(timer) {
100 clearTimeout(timer.timerId);
104 function doPlayback(eventList) {
105 var x = eventList.shift();
107 runtime.notify(x[0], x[1], x[2]);
109 if (eventList.length > 0) {
110 var delta = eventList[0][2] - time;
111 setTimeout(function() { doPlayback(eventList); }, delta);
115 function redrawGraphics() {
116 var graphicsFoldp = moduleRetValue.main.kids[0];
117 graphicsFoldp.recv(Date.now(), true, moduleRetValue.main.id);
120 var wrappedRuntime = {
122 runDelayed: wrapRunDelayed,
124 display: runtime.display,
126 addListener: runtime.addListener,
127 inputs: runtime.inputs
130 var moduleRetValue = module.make(wrappedRuntime);
133 moduleRetValue: moduleRetValue,
135 // debugger functions
137 restart: restartProgram,
138 getMaxSteps: getMaxSteps,
142 allNodes = flattenNodes(wrappedRuntime.inputs);
143 initialProgramState.nodeValues = saveNodeValues(allNodes);
144 initialProgramState.asyncTimers = asyncTimers.slice();
151function assert(bool, msg) {
153 throw "Assertion error: " + msg;
157function saveNodeValues(allNodes) {
160 allNodes.forEach(function(node) {
161 nodeValues.push({ value: node.value, id: node.id });
168function restoreNodeValues(allNodes, nodeStates) {
169 assert(allNodes.length == nodeStates.length, "saved program state has wrong length");
170 for (var i=0; i < allNodes.length; i++) {
171 var node = allNodes[i];
172 var state = nodeStates[i];
173 assert(node.id == state.id, "the nodes moved position");
175 node.value = state.value;
179function flattenNodes(nodes) {
180 var treeReduce = function(prev, cur, i, arr) {
181 var flatKids = cur.kids.reduce(treeReduce, []);
183 return prev.concat(flatKids);
186 return nodes.reduce(treeReduce, []);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list