clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
raspasov 2021-03-04T05:29:41.178400Z

@mike.j.cusack also to see fn bodies at the REPL, try

(set! *print-fn-bodies* true)

πŸ‘ 2
raspasov 2021-03-04T05:31:35.178700Z

=> (set! print-fn-bodies true) => + #object[cljs$core$PLUS β€œfunction cljs$core$PLUS(var_args){ var G__10823 = arguments.length; switch (G__10823) { case 0: return cljs.core.PLUS.cljs$core$IFn$_invoke$arity$0(); break; case 1: return cljs.core.PLUS.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); break; case 2: return cljs.core.PLUS.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); break; default: var args_arr__9263__auto__ = []; var len__9238__auto___10825 = arguments.length; var i__9239__auto___10826 = (0); while(true){ if((i__9239__auto___10826 < len__9238__auto___10825)){ args_arr__9263__auto__.push((arguments[i__9239__auto___10826])); var G__10827 = (i__9239__auto___10826 + (1)); i__9239__auto___10826 = G__10827; continue; } else { } break; } var argseq__9264__auto__ = (new cljs.core.IndexedSeq(args_arr__9263__auto__.slice((2)),(0),null)); return cljs.core.PLUS.cljs$core$IFn$invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq_9264__auto__); } }β€œ]

fsd 2021-03-04T14:32:26.187700Z

Hello There, [Clojure Newbe] I need help with this function, I have function in cljs for react frontend, it renders list of item from keys. I want to use if statement to check if key exists but when I use this following code to log the if statement , it by passes the if statement. Please Help! πŸ™‚

(defn parse-list [data]
        (map (fn [[k v]]
              (if (k = "Yesterday") (println "found")) 
                ($ List (name k))
             data))

p-himik 2021-03-04T14:36:50.189Z

Replace (k = "...") with (= k "...").

p-himik 2021-03-04T14:37:07.189200Z

Also, when is usually better in such cases.

βž• 2
Joar Gullestad Pettersen 2021-03-04T14:43:46.189500Z

also, looks like you are missing the end parentheses and looks like data should be moved out of the current parentheses

p-himik 2021-03-04T14:45:14.189700Z

Nah, the parens are alright. It's the indentation that's misleading.

fsd 2021-03-04T14:59:41.189900Z

thanks guys it worked

mikejcusack 2021-03-04T18:41:37.190200Z

https://guide.clojure.style/

2021-03-04T18:48:53.191400Z

Can someone with a better understanding of the "why"s of Clojurescript answer this for me? As a fairly new CLJS user, I'd expect to have the browser and JS APIs fully available to me, but after some research today I discovered that the document.cookie API seems to be read-only in CLJS. In vanilla JS you can both read and set a cookie with the same API:

document.cookie // gets cookies
document.cookie = "key=value" // sets a new cookie
And while I CAN read cookies with JS interop ...
js/document.cookie ;; gets cookies
... if I want to set a cookie, I have to require a separate module to do so:
(ns some-namespace)
(:require [goog.net.cookies])

(.set goog.net.cookies "key" "value")
So anyway ... what gives?

2021-03-04T18:50:26.192200Z

It's not the biggest problem in the world or anything, but it's got me wondering if there are other areas of JS <-> CLJS interop where I'm going to encounter similar situations.

dpsutton 2021-03-04T18:50:27.192300Z

https://cljs.info/cheatsheet/ check out the js-interop section for getting and setting

πŸ™‡ 1
dpsutton 2021-03-04T18:52:48.193100Z

that being said, those goog libs are a really nice set of libs that if they offer stuff it can really help you

2021-03-04T18:56:35.194Z

Cool, I appreciate it @dpsutton! I'll experiment with set! and see if I can get something working just so I can deepen my knowledge on the subject.

simongray 2021-03-05T08:23:08.203Z

I think you can also do (set! js/document.cookies "key=value")

p-himik 2021-03-05T09:38:26.206Z

Although . in this case, as in a regular get operation, works coincidentally and not deliberately. People recommend against using . in such scenarios but it also won't stop working.

2021-03-04T18:58:01.194400Z

Yep, it was exactly what I needed:

(set! (.-cookies js/document) "key=value")

mikejcusack 2021-03-04T19:16:13.195100Z

Which styling solutions are you guys using these days for CLJS?

p-himik 2021-03-04T20:07:26.195700Z

Apparently, you can also do it like this:

(set! js/document -cookies "key=value")
I'm not sure whether there's documentation for such usage, but the implementation explicitly allows it.

kongra 2021-03-04T20:12:26.196700Z

Hi, I use https://github.com/noprompt/garden

mikejcusack 2021-03-04T20:22:50.196900Z

And how do you handle being mobile-friendly?

kongra 2021-03-04T20:27:41.197100Z

I use cordova for mobile.

kongra 2021-03-04T20:29:03.197300Z

And for the mobile-oriented styling I use some custom routines that help me to maintain CSS for portrait/landscape/fullscreen orienations. It's on top of garden.

dnolen 2021-03-04T20:42:43.198Z

Finally got around to aligning w/ the latest Closure Compiler and a more recent snapshot of Google Closure Library

πŸ‘ 5
dnolen 2021-03-04T20:43:06.198500Z

if you're comfortable using ClojureScript directly via git deps - please give it a spin

πŸ‘ 2
2
mikejcusack 2021-03-05T10:35:05.209100Z

I'm noticing that Figwheel Main fails at the beginning due to the goog/log changes. It's complaining about the wrong number of arguments passed. It successfully compiled my app, including with the new npm require syntax, but when trying to recompile for hot load it hangs. And the behavior is the same without the new syntax.

dnolen 2021-03-05T15:14:30.225100Z

Figwheel needs to fix that

mikejcusack 2021-03-05T15:22:31.225300Z

Right. I've actually created some fixes for it myself already.

mikejcusack 2021-03-05T15:25:16.225500Z

What I'm struggling with right now is that the prod build with the master branch was 3MB, which is insane and was ~590KB before testing master. Now even going back to the latest stable it's still 3MB.

mikejcusack 2021-03-05T15:25:36.225700Z

I'm using webpack as per the CLJS docs

mikejcusack 2021-03-05T15:26:33.225900Z

I cleaned out all of my NPM deps and previous build just to make sure it's clean and no change.

mikejcusack 2021-03-05T15:27:37.226100Z

But testing a prod build using CLJSJS it's the same 627.4KB from first build.

mikejcusack 2021-03-05T15:41:07.226300Z

The 3MB is with building through figwheel-main (latest stable, not my changes). Building the prod build straight through CLJS it's 600.5KB, which is in line with the previous ~590.

mikejcusack 2021-03-05T15:47:11.226500Z

Now reupgrading to master branch it's at 600.5KB still. I'm confused

mikejcusack 2021-03-05T15:57:00.226700Z

Using the new require syntax with master the dev and prod builds are both 600.5KB

mikejcusack 2021-03-05T16:51:53.227300Z

All of those are not gzip'd. Gzip'd on master branch with the new require syntax and regular CLJS prod build is 100.74KB. I have no clue what happened with the sizes earlier, but at least it's back on track now. Whew.

dnolen 2021-03-05T17:07:49.227700Z

k cool

dnolen 2021-03-04T20:43:14.198800Z

what's on master will probably be the next release

mikejcusack 2021-03-04T20:45:20.199100Z

Ah, ok. I'm trying to avoid custom for that

2021-03-04T21:27:27.200200Z

I've been enjoying my emotion wrapper: https://github.com/dvingo/cljs-emotion

mikejcusack 2021-03-04T21:32:06.200500Z

I'm looking for a data-driven approach rather than macros.

isak 2021-03-04T21:50:17.200800Z

Tailwind, works great.

mikejcusack 2021-03-04T23:18:38.201600Z

I'm curious why there isn't a cljsjs package for that.

2021-03-04T23:30:21.201800Z

The styles in that emotion lib are plain data - you can compose them however you like