on 14ef71a 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;
10 var replace = Elm.Native.Utils.make(elm).replace;
12 function log(tag, value) {
13 var msg = tag + ': ' + show(value);
14 var process = process || {};
15 if (process.stdout) {
16 process.stdout.write(msg);
17 } else {
18 console.log(msg);
19 }
20 return value;
21 }
23 function tracePath(debugId, form) {
24 return replace([["debugTracePathId",debugId]], form);
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};