Fork me on GitHub
#clojurescript
<
2016-11-03
>
adambrosio03:11:15

@ag there is always doto

(doto "hello" (js/console.log "world!"))
; hello world!
;=> "hello"

tianshu06:11:28

How can i use a js library that not been packaged into one file? A library can contains multiple modules. With webpack only imported js will be packaged into dist js file. How can I achieve this in cljs?

vinodg10:11:03

how to write jquery in clojurescript?

raspasov10:11:02

@vinodg almost never a need to use jQuery when using ClojureScript, but I can understand the temptation; mid/long-term I would try to avoid it

dnolen13:11:04

@doglooksgood this can be done with :foreign-libs

kah0ona15:11:50

Question: I have a webapp, and when i compile my cljs to .js using leiningen for use in an uberjar, it compiles to app-min.js. But now users sometimes have to press CTRL+F5 or CMD+SHIFT+R or similar to prevent viewing the old version. I thought about compiling to app-min-<projectversionnumber>.js, but how do I do that in a project.clj file? Can I get the project version string somehow from the project.clj file? during uberjar building that is

kah0ona15:11:03

(I use leiningen)

jrheard15:11:26

@kah0ona the term you often see for this problem is “cache busting” - it affects css files as well as js files

jrheard15:11:05

i also found https://github.com/voxdolo/lein-buster but it has five commits and three stars so may not be the tool you end up choosing; might have some ideas/code you can use though

jrheard15:11:49

if you google around you should be able to find resources that give you solutions for doing this on arbitrary css/js files as well, unrelated to clojurescript

kah0ona15:11:25

aah thanks a lot

voxdolo15:11:25

I can speak to the above lib's use 😄

jrheard15:11:26

i don’t have a specific tool/solution, sorry - i just work on toy cljs projects 🙂

voxdolo15:11:34

we're using it in production for my startup

kah0ona15:11:51

okay will check it out then

voxdolo15:11:56

but I don't think many other folks have exactly the same need set in the clojure space for whatever reason

kah0ona15:11:10

yeah or they have an adhoc approach 🙂

kah0ona15:11:25

well it can be hacked in fairly easily come to think of it... 🙂

voxdolo15:11:31

also: boot has some of the same functionality and it's seen a lot of uptake in the CLJS community

voxdolo15:11:05

happy to entertain feature requests and PRs, in any case

kah0ona15:11:37

will check it out probably tomorrow

voxdolo15:11:03

cool, ping me if you need a hand. it's purpose-built for our needs right now, so there may be missing or nonobvious bits in the docs that I've missedd

borkdude16:11:36

Where is the best place to ask something about selectize.js?

p-himik17:11:00

Is there any way to call a JS constructor using cljs-oops?

jackmoch18:11:14

I’ve got a newbie syntax question here. In this chunk of code

(defn new-counter []
  (let [text (atom "")]
    (fn []
      [:div.row.container
        [:div.col-sm-10
          [:input.form-control {:type "text" :value @text
                                :on-change #(reset! text (-> % .-target .-value))}]]
          [:button.btn.btn-success {:on-click #(add-counter @text)} "Add"]])))
I believe I understand that the line #(reset! text (-> % .-target .-value)) is changing the value of the atom based on user input, but I don’t totally understand the (-> % .-target .-value) syntax. Would anyone be able to elaborate on that for me?

jjfine18:11:46

we can also write this as

(fn [event] (reset! text (-> event .-target .-value))

jjfine18:11:44

or even

(fn [event] (reset! text (.-value (.-target event)))

jjfine18:11:18

so the hash # is making an anonymous function whose first parameter is %

jjfine18:11:25

-> is the threading macro which i'm not sure how to explain succinctly

jr18:11:11

or even (fn [event] (reset! text (.. event -target -value)))

jjfine18:11:11

it takes a value and then threads it though the following forms

jjfine18:11:53

the (.-value (.-target event) are javascript concepts

jjfine18:11:30

an event in javascript has a target, the element that was changed

jjfine18:11:54

an element can have a value, in this case the input's text

jjfine18:11:58

that make sense @jackmoch

jackmoch18:11:11

Ah that helped immensely, so the event target’s value (i.e. what is type into the input element) resets the text of the atom to mirror the user’s input

jjfine18:11:27

yeah exactly

jackmoch18:11:53

Awesome, I really appreciate you taking the time to explain that in really great detail

darwin18:11:25

@p-himik I think you can retrieve constructor fn via oget and then use dot to call new: (let [c (oget o “my.ctor”)] (c. cp1 cp2 …))

jeffy19:11:12

Are there any community developed Clojurescript libraries for Grommet?

adamfrey20:11:47

I know you can extend js/jQuery with protocols, but can you do a similar thing for a jQuery Deferred object?

adamfrey20:11:28

I’m a little confused on how datatypes work in Javascript

dnolen20:11:35

@adamfrey only if you can get at the constructor for Deferred

dnolen20:11:45

the other way is that you can extend instances via specify!

adamfrey20:11:38

when I try

(extend-type (obj/get js/jQuery "Deferred")
  ...)

I get ERROR: clojure.lang.PersistentList cannot be cast to clojure.lang.Named.

adamfrey20:11:52

oh wait, duh

dnolen20:11:26

@adamfrey it may be that extend-type only currently works on symbols - not expressions

adamfrey20:11:45

yeah I realize I have to pull that out because of how the macro works

adamfrey20:11:15

I thought this might work

(def deferred (obj/get js/jQuery "Deferred"))

(extend-type deferred
  P
  (foo
    ([this] 123)))

(foo (deferred))
but it throws Uncaught Error: No protocol method P.foo defined for type object: [object Object]

dnolen20:11:34

@adamfrey right that doesn’t mean you’ve actually got the actual constructor

dnolen20:11:42

I have no idea how jQuery is written internally

adamfrey20:11:02

I’ll have to do more digging. Thanks for your help

mikekap23:11:59

hey i have a somewhat loaded question: how does cljs.compiler.api/compile-root handle .cljs and .cljc files with the same name?

dnolen23:11:45

@mikekap not a loaded question, but that’s just not going to work - one will win

dnolen23:11:49

more specifically - we use .cljs before .cljc files