Fork me on GitHub
#clojurescript
<
2021-01-15
>
Adam Helins14:01:34

Is there a way to detect in a macro whether the current compilation is advanced or not?

thheller14:01:57

in regular CLJS you could check the compiler options I guess

Adam Helins14:01:05

@theller In CLJS I could rely on goog.DEBUG but here it is about a macro behaving differently if it is being used in the context of an advanced build

thheller14:01:43

sorry by "regular CLJS" I meant not shadow-cljs 😉

thheller14:01:44

:advanced is technically not part of the CLJS compilation and only done on the final JS as a separate step

thheller14:01:55

so I don't know if the regular CLJS compiler sets anything you can check for this

thheller14:01:13

the idea was that you can look at the compiler options via the cljs.env/*compiler* atom

thheller14:01:29

shadow-cljs sets something in &env which you can check easily

(defmacro foo [bar]
  (if (= :release (:shadow.build/mode &env))
    `(release-code)
    `(dev-code)))

Adam Helins14:01:36

@thheller Excellent, both solutions are valid (checking &env and using cljs.env/*compiler)*

Adam Helins14:01:00

I'll use cljs.env as it is more general, thanks

hadils16:01:41

Hi! I am stumped with a n00b question. I want to add functionality to a React Native component. I am using the PEZ repo as my starting point and need to make a TextInput component have the .focus() method called when the custom prop :focus is true. I am using React Native, Expo, Re-frame and Reagent. I am completely at a loss as to how to get my own text-input component from an existing React Native TextInput component. Thanks in advance for any guidance you can give me!

Felipe Marques20:01:09

Hi, guys, I'm trying to extend a type with a protocol and I'm having problem to find out which type to use. When I run (type my-obj) I get #object[LocalDate] is this the right way?

fsd21:01:53

Hi there, I am new to Clojure I needed help converting js function to clojurescript . I have data coming from the API which is in PascalCased map key I am trying to get to readable state ex InventoryListNo ---> Inventory List No Since I am used to use to js this is what I have

function splitCamelCaseToString(s) {
    return s.split(/(?=[A-Z])/).join(' ');
}

splitCamelCaseToString("HelloWorld")

output: "Hello World"
This is what I created in CLJS
(defn splitCamelCaseToString [s]
      (->> (str/split s #"(?=[A-Z])")
      (str/join s))) 
output: HelloHelloWorldWorld
Someone please tell me what am I doing wrong

p-himik21:01:01

You used s twice - you're joining ["Hello" "World"] using "HelloWorld" as a separator.

fsd22:01:24

Ah I see thanks

emccue21:01:43

(defn split-camel-case-to-string [s]
  (.join (.split s #"(?=[A-Z])") " "))
     

fsd22:01:01

Thanks for your response I tried using this but I am getting empty return value

emccue21:01:54

@singhamritpal49 This is the literal translation

emccue22:01:41

To do it using functions in clojure.string

emccue22:01:08

(defn split-camel-case-to-string [s]
  (str/join (str/split s #"(?=[A-Z])") " "))

p-himik22:01:14

The order of the arguments to str/join is incorrect. Same in the next code block.

emccue22:01:17

and to use threading like you want

emccue22:01:51

(defn split-camel-case-to-string [s]
  (-> s
      (str/split #"(?=[A-Z])")
      (str/join " ")))

emccue22:01:15

(defn split-camel-case-to-string [s]
  (-> s
      (.split #"(?=[A-Z])")
      (.join " ")))