@mike.j.cusack also to see fn bodies at the REPL, try
(set! *print-fn-bodies* true)
=> (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__); } }β]
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))
Replace (k = "...")
with (= k "...")
.
Also, when
is usually better in such cases.
also, looks like you are missing the end parentheses and looks like data should be moved out of the current parentheses
Nah, the parens are alright. It's the indentation that's misleading.
thanks guys it worked
https://guide.clojure.style/#when-instead-of-single-branch-if
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?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.
https://cljs.info/cheatsheet/ check out the js-interop section for getting and setting
that being said, those goog libs are a really nice set of libs that if they offer stuff it can really help you
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.
I think you can also do (set! js/document.cookies "key=value")
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.
Yep, it was exactly what I needed:
(set! (.-cookies js/document) "key=value")
Which styling solutions are you guys using these days for CLJS?
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.Hi, I use https://github.com/noprompt/garden
And how do you handle being mobile-friendly?
I use cordova for mobile.
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.
Finally got around to aligning w/ the latest Closure Compiler and a more recent snapshot of Google Closure Library
if you're comfortable using ClojureScript directly via git deps - please give it a spin
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.
Figwheel needs to fix that
Right. I've actually created some fixes for it myself already.
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.
I'm using webpack as per the CLJS docs
I cleaned out all of my NPM deps and previous build just to make sure it's clean and no change.
But testing a prod build using CLJSJS it's the same 627.4KB from first build.
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.
Now reupgrading to master branch it's at 600.5KB still. I'm confused
Using the new require syntax with master the dev and prod builds are both 600.5KB
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.
k cool
what's on master will probably be the next release
Ah, ok. I'm trying to avoid custom for that
I've been enjoying my emotion wrapper: https://github.com/dvingo/cljs-emotion
I'm looking for a data-driven approach rather than macros.
Tailwind, works great.
I'm curious why there isn't a cljsjs package for that.
The styles in that emotion lib are plain data - you can compose them however you like