@@ -31,6 +31,32 @@ function init(display, container, module, ports, moduleToReplace) {
3131 // defining state needed for an instance of the Elm RTS
3232 var inputs = [];
3333
34+ /* OFFSET
35+ * Elm's time traveling debugger lets you interrupt the smooth flow of time
36+ * by pausing and continuing program execution. To ensure the user sees a
37+ * program that moves smoothly through the pause/continue time gap,
38+ * we need to adjsut the value of Date.now().
39+ */
40+ var timer = function() {
41+ var inducedDelay = 0;
42+
43+ var now = function() {
44+ return Date.now() - inducedDelay;
45+ };
46+
47+ var addDelay = function(d) {
48+ if (typeof d !== "number") {
49+ throw "addDelay must take a number (preferably an int), not: " + d
50+ }
51+ inducedDelay += d;
52+ return inducedDelay;
53+ }
54+
55+ return { now : now
56+ , addDelay : addDelay
57+ }
58+ }();
59+
3460 var updateInProgress = false;
3561 function notify(id, v) {
3662 if (updateInProgress) {
@@ -40,7 +66,7 @@ function init(display, container, module, ports, moduleToReplace) {
4066 'Definitely report this to <https://github.com/evancz/Elm/issues>\n');
4167 }
4268 updateInProgress = true;
43− var timestep = Date.now();
69+ var timestep = timer.now();
4470 for (var i = inputs.length; i--; ) {
4571 inputs[i].recv(timestep, id, v);
4672 }
@@ -72,6 +98,7 @@ function init(display, container, module, ports, moduleToReplace) {
7298 id:ElmRuntime.guid(),
7399 addListener:addListener,
74100 inputs:inputs,
101+ timer:timer,
75102 ports: { incoming:ports, outgoing:{}, uses:portUses }
76103 };
77104