clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Dominic Pearson 2021-04-07T10:30:03.001400Z

Hi. I am experimenting with figwheel-main. I am unable to connect to the REPL, and get the following error in the browser (see image). Am using lein, project.clj is as follows:

(defproject drp "0.1.0-SNAPSHOT"
  :description ""
  :license {:name "ISC"}
  :min-lein-version "2.7.1"
  :dependencies [[org.clojure/clojure "1.10.1"]
                 [org.clojure/clojurescript "1.10.844"]]
  :source-paths ["src"]
  :resource-paths ["target" "resources"]
  :clean-targets ^{:protect false} ["target/public"]
  :aliases {"fig"       ["trampoline" "run" "-m" "figwheel.main"]
            "fig:build" ["trampoline" "run" "-m" "figwheel.main" "-b" "dev" "-r"]
            "fig:min"   ["run" "-m" "figwheel.main" "-O" "advanced" "-bo" "dev"]
            "fig:test"  ["run" "-m" "figwheel.main" "-co" "test.cljs.edn" "-m" "drp.test-runner"]}
  :profiles {:dev {:dependencies [[com.bhauman/figwheel-main "0.2.12"]]
                   :resource-paths ["target"]
                   ;; need to add the compiled assets to the :clean-targets
                   :clean-targets ^{:protect false} ["target"]}})

Dominic Pearson 2021-04-07T10:30:46.001500Z

❯ lein fig
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
2021-04-07 12:26:53.252:INFO::main: Logging initialized @2632ms to org.eclipse.jetty.util.log.StdErrLog
[Figwheel] Compiling build figwheel-default-repl-build to "target/public/cljs-out/figwheel-default-repl-build-main.js"
[Figwheel] Successfully compiled build figwheel-default-repl-build to "target/public/cljs-out/figwheel-default-repl-build-main.js" in 0.937 seconds.
[Figwheel] Starting Server at <http://localhost:9500>
[Figwheel] Starting REPL
Prompt will show when REPL connects to evaluation environment (i.e. a REPL hosting webpage)
Figwheel Main Controls:
          (figwheel.main/stop-builds id ...)  ;; stops Figwheel autobuilder for ids
          (figwheel.main/start-builds id ...) ;; starts autobuilder focused on ids
          (figwheel.main/reset)               ;; stops, cleans, reloads config, and starts autobuilder
          (figwheel.main/build-once id ...)   ;; builds source one time
          (figwheel.main/clean id ...)        ;; deletes compiled cljs target files
          (figwheel.main/status)              ;; displays current state of system
Figwheel REPL Controls:
          (figwheel.repl/conns)               ;; displays the current connections
          (figwheel.repl/focus session-name)  ;; choose which session name to focus on
In the cljs.user ns, controls can be called without ns ie. (conns) instead of (figwheel.repl/conns)
    Docs: (doc function-name-here)
    Exit: :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Opening URL <http://localhost:9500>

Dominic Pearson 2021-04-07T10:31:15.001700Z

hangs here indefinitely. the only other file in the project is src/drp/core.cljs:

(ns ^:figwheel-hooks drp.core)

(println "This text is printed from src/drp/core.cljs. Go ahead and edit it and see reloading in action.")

thheller 2021-04-07T10:35:02.001900Z

the closure-library update coming with CLJS 1.10.844 changed a bunch of stuff and figwheel will need to be adjusted first

thheller 2021-04-07T10:35:18.002100Z

until then you should probably stick with the previous CLJS 1.10.773 version

Dominic Pearson 2021-04-07T10:35:21.002300Z

ah, I suspected it was version related. I'll downgrade for now, thanks!

thheller 2021-04-07T10:35:50.002500Z

or you can try the latest CLJS with a previous closure-library version. maybe that works too

Dominic Pearson 2021-04-07T10:36:21.002700Z

773 works a charm. no reason i version-bumped other than out of habit.

2021-04-07T11:34:08.003800Z

A most rn related question. I see some log messages (see pic). Is that generated by calling some rn function ?

2021-04-07T11:34:41.003900Z

When clicked, it becomes:

p-himik 2021-04-07T11:46:02.004100Z

Sente uses Timbre for logging.

p-himik 2021-04-07T11:46:18.004300Z

What Timbre ends up using in RN - no idea.

p-himik 2021-04-07T11:46:48.004500Z

Have you tried the default js/console?

2021-04-07T11:53:54.004700Z

(js/console.log) logs to the terminal where metro runs.

thheller 2021-04-07T11:54:10.004900Z

(js/console.warn "foo") might end up as such a popup?

👍 1
2021-04-07T11:54:55.005100Z

right.

2021-04-07T11:57:42.005400Z

I think (js/console) is a rather primitive functionality of the underlying js runtime. How does RN differentiate the output from log and warn? Does it monkey-patch console.warn to another function?

thheller 2021-04-07T11:59:00.005600Z

console is functionality they provide. it is not part of the runtime, or rather THEY made it part of the runtime

2021-04-07T11:59:59.005800Z

i see.

2021-04-07T12:10:19.006700Z

For re-frame-10x and re-frisk, is there any difference? Seems functionality-wise equal.

2021-04-07T13:57:53.007100Z

Just found out the popup is the logbox: https://reactnative.dev/docs/debugging#logbox

2021-04-07T14:38:40.008300Z

What to wrap/alias the timbre/info macro. But with the following output’s nothing.

2021-04-07T14:39:11.008800Z

(defmacro info [&amp; args]
  `(timbre/info ~@args))
(info “xxx”) gives (taoensso.timbre/info) and no output.

2021-04-07T14:56:27.009200Z

I see. macro shouldn’t occur in cljs file.

lilactown 2021-04-07T15:29:26.010400Z

does anyone know of a library that makes using JS tag templates easier to use in CLJS?

raspasov 2021-04-07T15:33:06.010500Z

Not exactly JS tags but makes using vectors, for example, much more performant: https://github.com/mfikes/cljs-bean

lilactown 2021-04-07T15:33:48.010900Z

yeah i'm familiar. doesn't help with tagged template strings

raspasov 2021-04-07T15:34:33.011400Z

Ah, ok; I misunderstood, I thought the #js {} stuff.

lilactown 2021-04-07T15:35:05.011600Z

it is an unfortunate collision in terms 😄

lilactown 2021-04-07T15:35:37.011800Z

I think that tagged templates in JS even serve similar purposes as reader tags in CLJS

raspasov 2021-04-07T15:35:48.012Z

How can one use Template Strings from CLJS at the moment? (I’ve never used them)

lilactown 2021-04-07T15:37:01.012200Z

in the basic case you can't and don't really need them; they can be trivially written using str: JS

`Hello, ${user}!
` CLJS
(str "Hello, " user "!")

raspasov 2021-04-07T15:37:30.012400Z

Right; so why are you asking? 🙂 Is there some perf. gain there?

lilactown 2021-04-07T15:37:35.012600Z

however, template tags can be useful in CLJS - see https://lit-html.polymer-project.org/

lilactown 2021-04-07T15:38:04.012900Z

there are some useful JS libraries that only expose their functionality via these tag templates

raspasov 2021-04-07T15:38:47.013100Z

My default is to be very skeptical of most JS libraries 🙂 (I know, I am biased)

lilactown 2021-04-07T15:39:17.013300Z

I'm personally not in the business of rewriting production ready DOM libs

raspasov 2021-04-07T15:39:18.013500Z

But perhaps, there’s some reason for the bias! 😄

raspasov 2021-04-07T15:39:31.013700Z

Sure;

raspasov 2021-04-07T15:40:07.013900Z

What’s the main use case for libs like those in CLJS? Poor man’s React?

lilactown 2021-04-07T15:40:53.014300Z

lit-html is a library for declaratively constructing DOM that doesn't involve a VDOM

lilactown 2021-04-07T15:41:05.014700Z

right, the way you would write them in CLJS would be something like:

(lit/TemplateResult. ["Hello, " "!"] user)
which is awkward.

raspasov 2021-04-07T15:41:46.014900Z

I see, so basically a simpler, less powerful React, if I understand correctly. With all the benefits and drawbacks of that.

lilactown 2021-04-07T15:41:54.015200Z

hence why I'm wondering if someone has already written a library for conveniently using them before I go publish one

nilern 2021-04-07T15:43:01.015400Z

Don't know but making a (tstr tag "Hello, " user "!") macro should be pretty easy

lilactown 2021-04-07T15:43:19.015600Z

I guess I'll do that then

lilactown 2021-04-07T15:45:39.015800Z

@raspasov right, lit-html has different tradeoffs; ostensibly it can be faster in what React calls the "commit phase," and doesn't bring with it a render/reconciliation mechanism. so if you're building your own way of handling state, composition and tracking changes, it can be lighter and easier to work with than React

raspasov 2021-04-07T15:51:00.016Z

@lilactown Got it, makes sense; Looks simple enough on the surface.

raspasov 2021-04-07T15:54:59.016200Z

I assume it’s DOM specific? (as in, no chance it will “easily work” on other platforms) I am aware that React needed a lot of platform specific work to make that happen, ofc.

lilactown 2021-04-07T15:58:52.016400Z

I'm not aware of anything that would allow lit templates to build UIs on e.g. native mobile. I think that the VDOM is a key ingredient to providing that generality

lilactown 2021-04-07T15:59:17.016600Z

although I think I remember hearing Svelte (which has no VDOM) could be used to build native UIs, so what do I know?

raspasov 2021-04-07T16:02:23.016900Z

Cool, I am not familiar either; just curious. Thanks for the discussion 👍

lilactown 2021-04-07T16:11:12.017500Z

Nice. that looks exactly what I was looking for 😄

lilactown 2021-04-07T16:11:17.017700Z

here's what I came up with: https://gist.github.com/lilactown/d4f87bad50a81384eb9fe609cfad60ef

lilactown 2021-04-07T16:12:08.017900Z

is there a difference between emitting an actual tagged template string like yours does vs. constructing the call to the template function via macro?

lilactown 2021-04-07T16:13:13.018100Z

i imagine the base case is faster (mine uses apply str on a lazy seq) but in the case when I'm calling e.g. lit's html tag I wasn't sure if there was a difference

thheller 2021-04-07T16:15:33.018300Z

the problem is getting the semantics of the template right. they have identity semantics for example, so each call to the tagged template will guarantee that the template is identical. it is not a new instance of some array

😱 1
thheller 2021-04-07T16:15:57.018500Z

many library such das lit-html rely on that to work since they need to associate some state with the template so they use it as the map key

thheller 2021-04-07T16:16:11.018700Z

if you just construct the array manually every time you break that

thheller 2021-04-07T16:16:29.018900Z

also there is this weird .raw property that some libs use

lilactown 2021-04-07T16:48:00.019300Z

wait so

html`&lt;div&gt;${bar}&lt;/div&gt;
` returns the same strings array on subsequent invocations?!

thheller 2021-04-07T16:48:52.019500Z

yes

lilactown 2021-04-07T16:49:34.019700Z

wow gotcha. yeah then you do really need to emit the template string, no real good way to get the interning behavior otherwise

lilactown 2021-04-07T16:49:39.019900Z

thanks! this has been very helpful

nilern 2021-04-07T16:55:41.020100Z

I think you could get the interning with some macro and global variable trickery

thheller 2021-04-07T16:58:06.020300Z

you can do that but it gets kinda annoying

nilern 2021-04-07T17:01:06.020600Z

Of course it would be better not to replicate badly what Closure already implements

lambduhhh 2021-04-07T18:07:44.024700Z

The context: Trying to overwrite carousel arrows with Fa-icons and the react bootstrap carousel API wants a DOM node as an argument to (prevIcon/nextIcon). Thankfully it is wrapped in a nice abstraction layer where one of the following will take place. Currently using hiccup to render the html. The question: Should I do this using interop, https://github.com/jeluard/hipo or https://github.com/plumatic/dommy ? I have some experience with dommy/interop but was wondering what yall think?

p-himik 2021-04-07T18:13:35.025200Z

FWIW, I would definitely use interop or, maybe, something from goog, if it exists.

👍 1
lambduhhh 2021-04-07T18:18:04.025500Z

OK cool. I kinda knew in my heart prob what I should do for a lil one off like this. Thx for the push to not be a wuss 😂 (interop=grumble grumble lol)

thheller 2021-04-07T18:20:35.025700Z

I don't think it wants an actual DOM node? pretty sure it wants a react element?

thheller 2021-04-07T18:21:05.025900Z

https://react-bootstrap.github.io/components/carousel/#carousel-props this is what you are asking about right?

thheller 2021-04-07T18:22:35.026200Z

for reagent that would be [:&gt; Carousel {:nextIcon (reagent/as-element [:span "next"]) ...} ...]

👍 1