Created
January 28, 2016 06:25
-
-
Save j1mr10rd4n/7dfa7e9b6b6eaaf813f0 to your computer and use it in GitHub Desktop.
Clojurescript port of the debug demo from the google closure library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
; Clojurescript port of the debug demo from the google closure library | |
; at https://github.com/google/closure-library/blob/master/closure/goog/demos/debug.html | |
; | |
(ns goog-debug-demo.goog-debug-demo | |
(:require [goog.debug :as debug] | |
[goog.log :as log]) | |
(:import [goog.debug FancyWindow] | |
[goog.log Level])) | |
; Person - a simple person object. | |
(deftype Person [name age address children] | |
Object | |
(addChild [_ kid] (.push children kid)) | |
(setAddress [this address] (aset this "address" address)) | |
(toString [_] (str "Person name: " name " Age: " age))) | |
; Create the debug window. | |
(def debugWindow (FancyWindow. "main")) | |
; Create a logger. | |
(def theLogger (log/getLogger "demo")) | |
; Create a simple object. | |
(def someone #js {"name" "joe" | |
"age" 33 | |
"gender" "m" | |
"kids" ["jen" "sam" "oliver"] | |
"address" "233 Great Road, Axtonhammer, MD"}) | |
; Now create a Person object to demonstrate expose w/functions. | |
(def pObj (Person. "fred" 2 nil #js [])) | |
;; | |
;; Demonstrate the debug options. | |
;; | |
(defn demoDebug [] | |
(.setEnabled debugWindow true) | |
(.init debugWindow) | |
; Show the object, note that it wil output '[object Object]'. | |
(log/info theLogger someone) | |
; Use expose to walk through the object and show all data. | |
(log/info theLogger (str "Person: " (debug/expose someone))) | |
; Add a child, and an address | |
(.addChild pObj someone) | |
(.setAddress pObj "1 broadway, ny, ny") | |
; The toString will be called. | |
(log/info theLogger (str "toString: " pObj)) | |
; Does not show the functions by default. | |
(log/info theLogger (str "expose (no functions): " (debug/expose pObj))) | |
; You can specify false if you really want to. | |
(log/info theLogger (str "expose (no functions): " (debug/expose pObj false))) | |
; Shows the functions as well. | |
(log/info theLogger (str "expose (no functions): " (debug/expose pObj true))) | |
; Show deepExpose, which walks recursively through data. | |
(log/info theLogger (str "deepExpose (no functions): " (debug/deepExpose pObj))) | |
; You can specify false if you really want to. | |
(log/info theLogger (str "deepExpose (no functions): " (debug/deepExpose pObj false))) | |
(log/info theLogger (str "deepExpose (w/functions): " (debug/deepExpose pObj true))) | |
(log/log theLogger Level.SHOUT "shout") | |
(log/error theLogger "severe") | |
(log/warning theLogger "warning") | |
(log/info theLogger "info") | |
(log/fine theLogger "fine")) | |
(demoDebug) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment