Fork me on GitHub
#clojurescript
<
2021-03-04
>
fsd14:03:26

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-himik14:03:50

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

p-himik14:03:07

Also, when is usually better in such cases.

6
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

p-himik14:03:14

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

fsd14:03:41

thanks guys it worked

afry18:03:53

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?

afry18:03:26

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

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

🙇 3
dpsutton18:03:48

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

afry18:03:35

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.

afry18:03:01

Yep, it was exactly what I needed:

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

p-himik20:03:26

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.

simongray08:03:08

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

p-himik09:03:26

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.

mikejcusack19:03:13

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

dvingo21:03:27

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

mikejcusack21:03:06

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

isak21:03:17

Tailwind, works great.

mikejcusack23:03:38

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

dvingo23:03:21

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

mikejcusack00:03:27

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.

dvingo03:03:55

It works really well with reagent: https://dvingo.github.io/cljs-emotion/#!/dv.cljs_emotion.reagent_cards see the last card on that page for an example that doesn't use defstyled

mikejcusack20:03:50

And how do you handle being mobile-friendly?

kongra20:03:41

I use cordova for mobile.

kongra20:03:03

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.

mikejcusack20:03:20

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

dnolen20:03:43

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

👍 15
dnolen20:03:06

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

👍 6
cljs 6
mikejcusack10:03:05

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.

dnolen15:03:30

Figwheel needs to fix that

mikejcusack15:03:31

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

mikejcusack15:03:16

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.

mikejcusack15:03:36

I'm using webpack as per the CLJS docs

mikejcusack15:03:33

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

mikejcusack15:03:37

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

mikejcusack15:03:07

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.

mikejcusack15:03:11

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

mikejcusack15:03:00

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

mikejcusack16:03:53

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.

dnolen20:03:14

what's on master will probably be the next release