on master help sign in
brought the timer down to the instance scope (elm.timer.now())
f8048beMichael James
libraries/Native/Signal/Signal.js+1−1
@@ -138,7 +138,7 @@ Elm.Native.Signal.make = function(elm) {
138 }
138 }
139
139
140 function timestamp(a) {
140 function timestamp(a) {
141− function update() { return Utils.Tuple2(Elm.timer.now(), a.value); }
141+ function update() { return Utils.Tuple2(elm.timer.now(), a.value); }
142 return new LiftN(update, [a]);
142 return new LiftN(update, [a]);
143 }
143 }
144
144
libraries/Native/Signal/Time.js+4−4
@@ -12,10 +12,10 @@ Elm.Native.Time.make = function(elm) {
12
12
13 function fpsWhen(desiredFPS, isOn) {
13 function fpsWhen(desiredFPS, isOn) {
14 var msPerFrame = 1000 / desiredFPS;
14 var msPerFrame = 1000 / desiredFPS;
15− var prev = Elm.timer.now(), curr = prev, diff = 0, wasOn = true;
15+ var prev = elm.timer.now(), curr = prev, diff = 0, wasOn = true;
16 var ticker = NS.input(diff);
16 var ticker = NS.input(diff);
17 function tick(zero) { return function() {
17 function tick(zero) { return function() {
18− curr = Elm.timer.now();
18+ curr = elm.timer.now();
19 diff = zero ? 0 : curr - prev;
19 diff = zero ? 0 : curr - prev;
20 prev = curr;
20 prev = curr;
21 elm.notify(ticker.id, diff);
21 elm.notify(ticker.id, diff);
@@ -35,9 +35,9 @@ Elm.Native.Time.make = function(elm) {
35 }
35 }
36
36
37 function every(t) {
37 function every(t) {
38− var clock = NS.input(Elm.timer.now());
38+ var clock = NS.input(elm.timer.now());
39 function tellTime() {
39 function tellTime() {
40− elm.notify(clock.id, Elm.timer.now());
40+ elm.notify(clock.id, elm.timer.now());
41 elm.runDelayed(tellTime, t);
41 elm.runDelayed(tellTime, t);
42 }
42 }
43 elm.runDelayed(tellTime, t);
43 elm.runDelayed(tellTime, t);
libraries/Native/Signal/Touch.js+2−2
@@ -61,11 +61,11 @@ Elm.Native.Touch.make = function(elm) {
61 dict.insert(e.identifier,
61 dict.insert(e.identifier,
62 {x: point._0,
62 {x: point._0,
63 y: point._1,
63 y: point._1,
64− t: Elm.timer.now()});
64+ t: elm.timer.now()});
65 }
65 }
66 function end(e) {
66 function end(e) {
67 var t = dict.remove(e.identifier);
67 var t = dict.remove(e.identifier);
68− if (Elm.timer.now() - t.t < tapTime) {
68+ if (elm.timer.now() - t.t < tapTime) {
69 hasTap = true;
69 hasTap = true;
70 tap = {_:{}, x:t.x, y:t.y};
70 tap = {_:{}, x:t.x, y:t.y};
71 }
71 }
runtime/Debugger.js+1−1
@@ -118,7 +118,7 @@ function debugModule(module, runtime) {
118
118
119 function setContinue(position) {
119 function setContinue(position) {
120 var timerDelay = Date.now() - now;
120 var timerDelay = Date.now() - now;
121− Elm.timer.addDelay(timerDelay);
121+ runtime.timer.addDelay(timerDelay);
122 programPaused = false;
122 programPaused = false;
123 if (position > 0) {
123 if (position > 0) {
124 // If we're not unpausing at the head, then we need to dump the
124 // If we're not unpausing at the head, then we need to dump the
runtime/Init.js+25−24
@@ -27,33 +27,33 @@ Elm.worker = function(module, ports) {
27 return init(ElmRuntime.Display.NONE, {}, module, ports || {});
27 return init(ElmRuntime.Display.NONE, {}, module, ports || {});
28};
28};
29
29
30−/* OFFSET
30+function init(display, container, module, ports, moduleToReplace) {
31− * Elm's time traveling debugger lets you interrupt the smooth flow of time
31+ // defining state needed for an instance of the Elm RTS
32− * by pausing and continuing program execution. To ensure the user sees a
32+ var inputs = [];
33− * program that moves smoothly through the pause/continue time gap,
34− * we need to adjsut the value of Date.now().
35− */
36−Elm.timer = function() {
37− var inducedDelay = 0;
38
33
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+ */
39− var now = function() {
40+ var timer = function() {
40− return Date.now() - inducedDelay;
41+ var inducedDelay = 0;
41− };
42
42
43− var addDelay = function(d) {
43+ var now = function() {
44− var delay = (d|0);
45− inducedDelay += delay;
46− return inducedDelay;
44+ return Date.now() - inducedDelay;
47− }
45+ };
48
46
49− return { now : now
47+ var addDelay = function(d) {
50− , addDelay : addDelay
48+ var delay = (d|0);
51− }
49+ inducedDelay += delay;
50+ return inducedDelay;
52−}();
51+ }
53
52
54−function init(display, container, module, ports, moduleToReplace) {
53+ return { now : now
55− // defining state needed for an instance of the Elm RTS
54+ , addDelay : addDelay
56− var inputs = [];
55+ }
56+ }();
57
57
58 var updateInProgress = false;
58 var updateInProgress = false;
59 function notify(id, v) {
59 function notify(id, v) {
@@ -64,7 +64,7 @@ function init(display, container, module, ports, moduleToReplace) {
64 'Definitely report this to <https://github.com/evancz/Elm/issues>\n');
64 'Definitely report this to <https://github.com/evancz/Elm/issues>\n');
65 }
65 }
66 updateInProgress = true;
66 updateInProgress = true;
67− var timestep = Elm.timer.now();
67+ var timestep = timer.now();
68 for (var i = inputs.length; i--; ) {
68 for (var i = inputs.length; i--; ) {
69 inputs[i].recv(timestep, id, v);
69 inputs[i].recv(timestep, id, v);
70 }
70 }
@@ -96,6 +96,7 @@ function init(display, container, module, ports, moduleToReplace) {
96 id:ElmRuntime.guid(),
96 id:ElmRuntime.guid(),
97 addListener:addListener,
97 addListener:addListener,
98 inputs:inputs,
98 inputs:inputs,
99+ timer:timer,
99 ports: { incoming:ports, outgoing:{}, uses:portUses }
100 ports: { incoming:ports, outgoing:{}, uses:portUses }
100 };
101 };
101
102