Fork me on GitHub

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))


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


Also, when is usually better in such cases.

Joar Gullestad Pettersen14:03:46

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


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 [])

(.set "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.

dpsutton18:03:27 check out the js-interop section for getting and setting

🙇 3

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.


Yep, it was exactly what I needed:

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


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.


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.


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


I've been enjoying my emotion wrapper:


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


I'm referring to the use of macros like defstyled. I'm looking for something that will fit in nicely with the hiccup in Reagent.


It works really well with reagent:!/dv.cljs_emotion.reagent_cards see the last card on that page for an example that doesn't use defstyled


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.


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


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

👍 15

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

👍 6
cljs 6

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.


what's on master will probably be the next release