Fork me on GitHub
#clojurescript
<
2020-04-19
>
jaihindhreddy14:04:55

Are persistent datastructures always included, even in advanced mode? (js/console "hello, world") should just translate to console.log("hello, world") I know hello-world size is not the thing that matters for real apps. I was just curious what the 95K (pre gzip) bundle contains.

thheller14:04:56

@jaihindhreddy some code in cljs.core prevents removal of more code but this is fixed in current cljs master so will be fixed in next release. but yes any real world app will have all that code anyways.

sova-soars-the-sora15:04:19

(def current-state (atom :start))

sova-soars-the-sora15:04:10

(get other-atom current-state) does not work, saying Uncaught Invariant Violation: Objects are not valid as a React child o.o

sova-soars-the-sora15:04:58

i'm trying to store the atom value as a keyword, to then do a lookup in another atom. am i doing it incorrectly?

sova-soars-the-sora15:04:28

(deref'd of course!)

sova-soars-the-sora15:04:42

how would you implement a state machine in clojurescript using one atom for states and the other for current-state?

sova-soars-the-sora15:04:49

that's my goal right now 🙂

sova-soars-the-sora15:04:57

I still don't know the edges where clojurescript != clojure. I expect a keyword to be a keyword to be a keyword, but apparently it becomes something else along the way

lilactown16:04:43

Your code is wrong in some other place. The “Object is not a React element” error means you’re passing something to React that isn’t a react element.

lilactown16:04:47

It has nothing to do with keywords specifically

sova-soars-the-sora15:04:27

that is useful, but also overkill for what i'm doing 😄

sova-soars-the-sora16:04:52

hmm, maybe keywords are just not good to use in CLJS?

dpsutton16:04:35

what do you mean you expect a keyword to be a keyword but it becomes something else? what is "the way" here?

dpsutton16:04:26

@sova I've never run into any issues with keywords with cljs and I expect that they are quite heavily used by all clojurescript users just as they are in Clojure

👍 4
fricze16:04:26

I’m trying to exactly understand using macros in ClojureScript. I know that macros are written and evaluated in Clojure, but I can’t wrap my how eval works in macros called from ClojureScript. Let’s say I have this code:

(ns app.macro.clj)

(defmacro defthing [name thing]
  `(def ~name ~(eval thing)))
(ns app.core.cljs
  (:require-macros [app.macro.clj :refer [defthing]]))

(defthing hello (str "hello" " world!"))
This will not work because compiler is Unable to resolve symbol: str in this context. What bindings are available for eval run in macro called in ClojureScript file? Are there any? I hope my question is understendable

lilactown16:04:18

you probably have to namespace prefix it. it might not do what you want

lilactown16:04:39

(defthing hello (clojure.core/str “hello” “world!”))

fricze16:04:15

I know that prefixing might help but I still don’t understand why it happens. str exists in clojure.core and in cljs.core so why can’t eval access it?

lilactown16:04:58

all symbols have to be prefixed, but all namespaces implicitly have a refer-all to

lilactown16:04:06

clojure.core

lilactown16:04:24

eval doesn’t get this auto-refer-all behavior

sova-soars-the-sora16:04:08

@dpsutton thanks i will try and show an example

sova-soars-the-sora16:04:28

the clojurescript interop page says don't expect identical? to work on keywords, but that's not exactly the problem i was having

sova-soars-the-sora17:04:04

For example,

(def t-current-state (atom :start))
(def t-all-states (atom {:start [:noun :verb]
						 :noun [:verb :particle :nona :da]
						 :verb [:noun :accept]
						 :particle [:noun :verb]
						 :nona :noun
						 :da :accept}))

(.log js/console "test: " (get @t-all-states @t-current-state))
is there some way I can have it spit out a clean [:noun :verb] result?

dpsutton17:04:27

Log logs JavaScript objects do it peeks behind the curtain so to speak

Aron20:04:08

Is there something specific to read browser cookies or I should use js interop directly?

Aron20:04:59

I tried to google this but all I get is reagent and ring and similar very specific examples (I use neither)

lilactown20:04:08

tbh you could probably just copy https://github.com/reagent-project/reagent-utils/blob/master/src/reagent/cookies.cljs into your project, it's not dependent on reagent at all

Aron20:04:36

thanks, I didn't see this specific example, will try it out now

Aron20:04:59

It's very education, if I can understand what is happening 😄

Aron20:04:07

not quite there yet

Diego22:04:29

Hello, I've started using cljs (with shadow-cljs, don't know if that is important), but when I try to do something like (keys nil) , I get an error, though I'd be expecting a similar behaviour to clj (which simply returns nil). Why is that?

justin22:04:33

What's the error? Performing (keys nil) returns nil on https://clojurescript.io/

Diego23:04:43

sorry, I am no longer getting that :thinking_face: