Comments (4)
Perhaps this could result in a better enable-console-print!
from cljs-devtools.
I had no time to look into this yet. I believe you could achieve something similar with String
object instead of using just plain js strings. The String
object should be able to hold cljs metadata and should be presented as string in standard consoles.
Try something like this (from top of my head):
(specify! (js/String. (pr-str data)) IMeta (-meta [_] data)))))
from cljs-devtools.
That partially solves the "string with metadata" issue.
cljs.user=>
(defn data-str [data]
(binding [*print-level* 3 *print-length* 5]
(specify! (js/String. (pr-str data)) IMeta (-meta [_] data))))
cljs.user=> (data-str {:a (range 10)})
#object[String {:a (0 1 2 3 4 ...)}]
cljs.user=> (meta (data-str {:a (range 10)}))
{:a (0 1 2 3 4 5 6 7 8 9)}
But the console output associated with String objects isn't what we were hoping for...
Test: Just console.log(new String("I am a string"))
in Chrome console (no cljs devtools)
Test: Just (js/console.log (js/String. "I am a string"))
in metro bundler log
Test: Just (js/console.log (data-str {:a (range 10)}))
in metro bundler log
Test: Just (js/console.log (data-str {:a (range 10)}))
in chrome console with cljs devtools
from cljs-devtools.
This is the best I've come up with
(defn log-data [& data]
(binding [*print-level* 3 *print-length* 5]
(let [s (apply pr-str data)
d (specify! #js [] IMeta (-meta [_] data))]
(js/console.log s d))))
(log-data :this {:is "a" :test (range 100)})
It looks fine from a metro bundler terminal.
LOG :this {:is "a", :test (0 1 2 3 4 ...)} []
I suspect cljs-devtools could be made to handle the "array with meta" better.
Still a bit ugly from console without devtools...
from cljs-devtools.
Related Issues (20)
- Is devtools appending a line to js source? HOT 1
- Rendering issue in devtools scope tree HOT 7
- TypeError: target.addEventListener is not a function HOT 1
- Symbolic values (##NaN, ##Inf) rendered as null when formatted HOT 3
- Custom formatters are being removed from Chrome? HOT 22
- Annotating display elements with path information HOT 8
- Should (prn my-map) be doing a pretty print in console? mine doesn't... HOT 1
- Print maps sorted
- Can this be used to transformation EDN to be printed inside document.body?
- "Store as Global Variable" option vanishes
- Compile Warning when building with ClojureScript 1.10.896 HOT 1
- Path generation taking long in extremely large maps
- Render in repl HOT 1
- Path indexes are not correct after max-number-body-items limit
- lein demo throws HOT 3
- Generalize code and documentation to include Firefox HOT 1
- Regression: Firefox no longer prints structures in 1.0.7 HOT 5
- Add steps for shadow-cljs build HOT 1
- Color scheme is hard to read in dark mode HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cljs-devtools.