on master help sign in
brought the timer down to the instance scope (elm.timer.now())
commitf8048bea4c4940afa353dedfb90fe05468b1673e authorMichael James <michael@michaelbjames.com> dateMon 21 Jul 2014, 15:29 (12 years ago) parent494dfdb
5 files changed+33−32
libraries/Native/Signal/Signal.js+1−1 libraries/Native/Signal/Time.js+4−4 libraries/Native/Signal/Touch.js+2−2 runtime/Debugger.js+1−1 runtime/Init.js+25−24
libraries/Native/Signal/Signal.js+1−1
@@ -138,7 +138,7 @@ Elm.Native.Signal.make = function(elm) {
138138 }
139139
140140 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); }
142142 return new LiftN(update, [a]);
143143 }
144144
libraries/Native/Signal/Time.js+4−4
@@ -12,10 +12,10 @@ Elm.Native.Time.make = function(elm) {
1212
1313 function fpsWhen(desiredFPS, isOn) {
1414 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;
1616 var ticker = NS.input(diff);
1717 function tick(zero) { return function() {
18− curr = Elm.timer.now();
18+ curr = elm.timer.now();
1919 diff = zero ? 0 : curr - prev;
2020 prev = curr;
2121 elm.notify(ticker.id, diff);
@@ -35,9 +35,9 @@ Elm.Native.Time.make = function(elm) {
3535 }
3636
3737 function every(t) {
38− var clock = NS.input(Elm.timer.now());
38+ var clock = NS.input(elm.timer.now());
3939 function tellTime() {
40− elm.notify(clock.id, Elm.timer.now());
40+ elm.notify(clock.id, elm.timer.now());
4141 elm.runDelayed(tellTime, t);
4242 }
4343 elm.runDelayed(tellTime, t);
libraries/Native/Signal/Touch.js+2−2
@@ -61,11 +61,11 @@ Elm.Native.Touch.make = function(elm) {
6161 dict.insert(e.identifier,
6262 {x: point._0,
6363 y: point._1,
64− t: Elm.timer.now()});
64+ t: elm.timer.now()});
6565 }
6666 function end(e) {
6767 var t = dict.remove(e.identifier);
68− if (Elm.timer.now() - t.t < tapTime) {
68+ if (elm.timer.now() - t.t < tapTime) {
6969 hasTap = true;
7070 tap = {_:{}, x:t.x, y:t.y};
7171 }
runtime/Debugger.js+1−1
@@ -118,7 +118,7 @@ function debugModule(module, runtime) {
118118
119119 function setContinue(position) {
120120 var timerDelay = Date.now() - now;
121− Elm.timer.addDelay(timerDelay);
121+ runtime.timer.addDelay(timerDelay);
122122 programPaused = false;
123123 if (position > 0) {
124124 // 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) {
2727 return init(ElmRuntime.Display.NONE, {}, module, ports || {});
2828};
2929
30−/* OFFSET
31− * Elm's time traveling debugger lets you interrupt the smooth flow of time
32− * by pausing and continuing program execution. To ensure the user sees a
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;
30+function init(display, container, module, ports, moduleToReplace) {
31+ // defining state needed for an instance of the Elm RTS
32+ var inputs = [];
3833
39− var now = function() {
40− return Date.now() - inducedDelay;
41− };
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;
4242
43− var addDelay = function(d) {
44− var delay = (d|0);
45− inducedDelay += delay;
46− return inducedDelay;
47− }
43+ var now = function() {
44+ return Date.now() - inducedDelay;
45+ };
4846
49− return { now : now
50− , addDelay : addDelay
51− }
52−}();
47+ var addDelay = function(d) {
48+ var delay = (d|0);
49+ inducedDelay += delay;
50+ return inducedDelay;
51+ }
5352
54−function init(display, container, module, ports, moduleToReplace) {
55− // defining state needed for an instance of the Elm RTS
56− var inputs = [];
53+ return { now : now
54+ , addDelay : addDelay
55+ }
56+ }();
5757
5858 var updateInProgress = false;
5959 function notify(id, v) {
@@ -64,7 +64,7 @@ function init(display, container, module, ports, moduleToReplace) {
6464 'Definitely report this to <https://github.com/evancz/Elm/issues>\n');
6565 }
6666 updateInProgress = true;
67− var timestep = Elm.timer.now();
67+ var timestep = timer.now();
6868 for (var i = inputs.length; i--; ) {
6969 inputs[i].recv(timestep, id, v);
7070 }
@@ -96,6 +96,7 @@ function init(display, container, module, ports, moduleToReplace) {
9696 id:ElmRuntime.guid(),
9797 addListener:addListener,
9898 inputs:inputs,
99+ timer:timer,
99100 ports: { incoming:ports, outgoing:{}, uses:portUses }
100101 };
101102