on cc213fb help sign in
elk/libraries/Native/Debug.js
60 lines 1.7 kB history raw
1Elm.Native.Debug = {};
2Elm.Native.Debug.make = function(elm) {
3 elm.Native = elm.Native || {};
4 elm.Native.Debug = elm.Native.Debug || {};
5 if (elm.Native.Debug.values) return elm.Native.Debug.values;
6 if ('values' in Elm.Native.Debug)
7 return elm.Native.Debug.values = Elm.Native.Debug.values;
9 var show = Elm.Native.Show.make(elm).show;
11 function log(tag, value) {
12 var msg = tag + ': ' + show(value);
13 var process = process || {};
14 if (process.stdout) {
15 process.stdout.write(msg);
16 } else {
17 console.log(msg);
18 }
19 return value;
20 }
22 function tracePath(debugId, elem) {
23 elem.props.debugTracePathId = debugId;
24 return elem;
25 }
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();
42 function watch(tag, value) {
43 watchTracker.notify(tag, value);
44 return value;
45 }
47 function watchSummary(tag, f, value) {
48 watchTracker.notify(tag, f(value));
49 return value;
50 }
52 Elm.Native.Debug.values = {
53 tracePath: F2(tracePath),
54 log: F2(log),
55 watch: F2(watch),
56 watchSummary:F3(watchSummary),
57 watchTracker: watchTracker
58 };
59 return elm.Native.Debug.values = Elm.Native.Debug.values;
60};