on master help sign in
Add watch and watchSummary functions
5e1ae81Evan Czaplicki
libraries/Debug.elm+10
@@ -19,6 +19,16 @@ investigating bugs or performance problems.
19log : String -> a -> a
19log : String -> a -> a
20log = Native.Debug.log
20log = Native.Debug.log
21
21
22+{-| Watch a particular value in the reactive debugger.
23+-}
24+watch : String -> a -> a
25+watch = Native.Debug.watch
26+
27+{-| Watch a particular value in the reactive debugger.
28+-}
29+watchSummary : String -> (a -> b) -> a -> a
30+watchSummary = Native.Debug.watchSummary
31+
22{-| Trace an Element over time in the reactive debugger.
32{-| Trace an Element over time in the reactive debugger.
23-}
33-}
24trace : String -> Element -> Element
34trace : String -> Element -> Element
libraries/Native/Debug.js+29−1
@@ -8,7 +8,7 @@ Elm.Native.Debug.make = function(elm) {
8
8
9 var show = Elm.Native.Show.make(elm).show;
9 var show = Elm.Native.Show.make(elm).show;
10
10
11− function log(tag,value) {
11+ function log(tag, value) {
12 var msg = tag + ': ' + show(value);
12 var msg = tag + ': ' + show(value);
13 var process = process || {};
13 var process = process || {};
14 if (process.stdout) {
14 if (process.stdout) {
@@ -24,9 +24,37 @@ Elm.Native.Debug.make = function(elm) {
24 return elem;
24 return elem;
25 }
25 }
26
26
27+ function WatchTracker() {
28+ this.frames = [{}];
29+ this.clear = function() {
30+ this.watches = {};
31+ };
32+ this.pushFrame = function() {
33+ var lastFrame = this.frames[this.frames.length - 1];
34+ this.frames.push(lastFrame);
35+ }
36+ this.notify = function(tag, value) {
37+ this.frames[this.frames.length - 1][tag] = value;
38+ };
39+ }
40+ var watchTracker = new WatchTracker();
41+
42+ function watch(tag, value) {
43+ watchTracker.notify(tag, value);
44+ return value;
45+ }
46+
47+ function watchSummary(tag, f, value) {
48+ watchTracker.notify(tag, f(value));
49+ return value;
50+ }
51+
27 Elm.Native.Debug.values = {
52 Elm.Native.Debug.values = {
28 tracePath: F2(tracePath),
53 tracePath: F2(tracePath),
29 log: F2(log),
54 log: F2(log),
55+ watch: F2(watch),
56+ watchSummary:F3(watchSummary),
57+ watchTracker: watchTracker
30 };
58 };
31 return elm.Native.Debug.values = Elm.Native.Debug.values;
59 return elm.Native.Debug.values = Elm.Native.Debug.values;
32};
60};
runtime/Debugger.js+6−1
@@ -32,6 +32,7 @@ function debugModule(module, runtime) {
32 var programPaused = false;
32 var programPaused = false;
33 var recordedEvents = [];
33 var recordedEvents = [];
34 var asyncCallbacks = [];
34 var asyncCallbacks = [];
35+ var watchTracker = Elm.Native.Debug.make(runtime).watchTracker;
35
36
36 function wrapNotify(id, v) {
37 function wrapNotify(id, v) {
37 var timestep = Date.now();
38 var timestep = Date.now();
@@ -63,6 +64,7 @@ function debugModule(module, runtime) {
63 }
64 }
64
65
65 function recordEvent(id, v, timestep) {
66 function recordEvent(id, v, timestep) {
67+ watchTracker.pushFrame();
66 recordedEvents.push({ id:id, value:v, timestep:timestep });
68 recordedEvents.push({ id:id, value:v, timestep:timestep });
67 }
69 }
68
70
@@ -143,7 +145,8 @@ function debugModule(module, runtime) {
143 loadRecordedEvents: loadRecordedEvents,
145 loadRecordedEvents: loadRecordedEvents,
144 getPaused: getPaused,
146 getPaused: getPaused,
145 setPaused: setPaused,
147 setPaused: setPaused,
146− tracePath: tracePath
148+ tracePath: tracePath,
149+ watchTracker: watchTracker,
147 };
150 };
148}
151}
149
152
@@ -158,6 +161,7 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
158
161
159 function restartProgram() {
162 function restartProgram() {
160 resetProgram();
163 resetProgram();
164+ debugModule.watchTracker.clear();
161 debugModule.tracePath.clearTraces();
165 debugModule.tracePath.clearTraces();
162 debugModule.clearRecordedEvents();
166 debugModule.clearRecordedEvents();
163 debugModule.setPaused(false);
167 debugModule.setPaused(false);
@@ -262,6 +266,7 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
262 getHotSwapState: getHotSwapState,
266 getHotSwapState: getHotSwapState,
263 dispose: dispose,
267 dispose: dispose,
264 allNodes: debugModule.moduleNodes,
268 allNodes: debugModule.moduleNodes,
269+ watchTracker: debugModule.watchTracker,
265 mainNode: debugModule.moduleInstance.main
270 mainNode: debugModule.moduleInstance.main
266 };
271 };
267
272