clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
p-himik 2021-01-15T06:09:42.006300Z

Seems related: https://github.com/lambdaisland/kaocha-cljs/issues/25

Helins 2021-01-15T14:15:34.008200Z

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

thheller 2021-01-15T14:22:57.009100Z

in regular CLJS you could check the compiler options I guess

Helins 2021-01-15T14:31:05.011500Z

@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

thheller 2021-01-15T14:35:43.011900Z

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

thheller 2021-01-15T14:36:44.012400Z

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

thheller 2021-01-15T14:36:55.012900Z

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

thheller 2021-01-15T14:37:13.013300Z

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

thheller 2021-01-15T14:39:29.014Z

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

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

Helins 2021-01-15T14:54:36.015500Z

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

Helins 2021-01-15T14:55:00.016Z

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

hadils 2021-01-15T16:24:41.019400Z

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 Marques 2021-01-15T20:26:09.021700Z

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?

fsd 2021-01-15T21:18:53.028100Z

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-himik 2021-01-15T21:30:01.028600Z

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

emccue 2021-01-15T21:59:43.029700Z

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

emccue 2021-01-15T21:59:54.030Z

@singhamritpal49 This is the literal translation

emccue 2021-01-15T22:00:41.030700Z

To do it using functions in clojure.string

emccue 2021-01-15T22:01:08.031400Z

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

emccue 2021-01-15T22:01:17.031700Z

and to use threading like you want

emccue 2021-01-15T22:01:51.032300Z

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

emccue 2021-01-15T22:01:59.032500Z

or

emccue 2021-01-15T22:02:15.032800Z

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

fsd 2021-01-15T22:07:01.032900Z

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

fsd 2021-01-15T22:07:24.033100Z

Ah I see thanks

p-himik 2021-01-15T22:16:14.033300Z

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