Giter VIP home page Giter VIP logo

Comments (4)

olivergeorge avatar olivergeorge commented on August 17, 2024

Perhaps this could result in a better enable-console-print!

from cljs-devtools.

darwin avatar darwin commented on August 17, 2024

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.

olivergeorge avatar olivergeorge commented on August 17, 2024

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)

image

Test: Just (js/console.log (js/String. "I am a string")) in metro bundler log

image

Test: Just (js/console.log (data-str {:a (range 10)})) in metro bundler log

image

Test: Just (js/console.log (data-str {:a (range 10)})) in chrome console with cljs devtools

image

from cljs-devtools.

olivergeorge avatar olivergeorge commented on August 17, 2024

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.

image

Still a bit ugly from console without devtools...

image

from cljs-devtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.