Fork me on GitHub
#clojurescript
<
2016-02-19
>
trancehime02:02:53

This is strange

adamkowalski03:02:26

Hey, have you guys used setInterval and figwheel at the same time? It seems like every time figwheel reloads, the setInterval hook re registers the function and then it gets called multiple times instead of just once. Is there an alternative way to have an event happen every given number of milliseconds while avoiding the load time side effect of registering a callback function? Or at least have some way to prevent it from happening more than once.

nidu03:02:21

@adamkowalski: you can declare setInterval inside of defonce i guess. Alse you can call setInterval on some component mount (root component for example) and call clearInterval on unmount

noonian04:02:57

I usually have all my setup code initiated by a single function that I export. Then in my html I invoke that setup function. That way figwheel never reloads any code that has side effects.

adamkowalski04:02:02

thanks a lot guys! this will really help me

adamkowalski04:02:29

also what is a good way to talk about time in general? In Elm there was a signal abstraction, so you could get the total time that had passed since your app began, as well as thing like time deltas, meaning you could get how much time has passed since the last time your function was called.

adamkowalski04:02:11

I am trying to make animations easier to reason about without using css. So I would store the properties of elements that need to change over time in the app state atom, and when some event triggers an animation I would change the model using the time deltas to make the animation last the correct duration

adamkowalski04:02:53

should I use requestAnimationFrame?

nidu05:02:19

Are you using some React based lib? Doesn't d3 suit your needs?

adamkowalski05:02:33

Yeah I am using Om Next, but there doesnt seem to be a mechanism to talk about time explicitly, at least not that I have noticed

adamkowalski05:02:44

I believe the purpose of things like a transactor, or core async is to use queues and separate when things happen from what things happen.

trancehime06:02:45

how is it possible to have some button "Login" be clicked when user hits 'Enter' key when using Reagent? I tried on-key-press but nothing

mikethompson07:02:33

From http://reagent-project.github.io/ this sample:

[:input (merge props
                     {:type "text" :value @val :on-blur save
                      :on-change #(reset! val (-> % .-target .-value))
                      :on-key-down #(case (.-which %)
                                      13 (save)
                                      27 (stop)
                                      nil)})]

trancehime07:02:08

I just have a simple button though that's not attached to any form, would i have to convert all to a form?

adamkowalski07:02:18

[:button {:on-key-down #(when (= (. -which %) 13) do-the-thing)}]

trancehime07:02:47

[:span.primary.hollow.button {:on-click #(auth/login! @username @password) :on-key-down #(when (= (. -keyCode %) 13) (auth/login! @username @password))} "Log in"] For soem reason, this is not working

adamkowalski07:02:12

first replace (auth/login! @username @password) with (.log js/console “i was clicked”)

adamkowalski07:02:23

click the button and check if anything gets logged

adamkowalski07:02:39

but also on key down wont realaly work on the button

adamkowalski07:02:44

unless it is being focused

adamkowalski07:02:01

I think what you really want to do is attach that to the input which is being used

adamkowalski07:02:55

like the button should fire the event when it is clicked OR if the user is typing in the input and they press enter then you should fire the event

trancehime07:02:11

ohhhh that makes sense.

adamkowalski07:02:36

yeah ignore my above code

adamkowalski07:02:40

idk why i wronte [:button

adamkowalski07:02:43

that makes no sense

adamkowalski07:02:58

[:button {:on-click #(.log js/console “i was clicked”)}]

trancehime07:02:08

that worked by the way ("i was clicked")

adamkowalski07:02:37

[:input {:on-key-down #(when (= (. -keyCode %) 13) (.log js/console “enter was typed”))}]

adamkowalski07:02:29

and also you should have an on change handler which takes the current value of the text box and then changes your atom app state

adamkowalski07:02:45

and finally you could set the value of the input to always reflect the value of the model

trancehime07:02:44

yeah I already do that simple_smile

trancehime07:02:36

There we go, thanks for your help

kmandrup08:02:20

I've seen many developers stumble on this, including myself... feel free to contribute and correct.

Petrus Theron09:02:02

js->clj does not seem to keywordize-keys for nested structures. With ClojureScript 1.7.228, I get:

(js->clj #js [{"hi" "there"}] :keywordize-keys
  true)
=> [{"hi" "there”}]
Instead of [{:hi “there”}] as expected. Or am I doing something wrong?

Petrus Theron09:02:37

but (js->clj #js {"hi" "there"} :keywordize-keys true) returns {:hi "there”}

solicode09:02:15

@petrus Maybe because the entire thing isn’t a JS object? How about if you did this? #js [#js {"hi" "there”}]

solicode09:02:41

What I mean is, I don’t think #js is recursive.

dnolen14:02:57

if you’re a student a reminder to submit GSoC project ideas http://dev.clojure.org/display/community/Project+Ideas+2016

dnolen15:02:59

also if you’re interested in being a mentor you can propose an idea you would like to mentor

dnolen15:02:17

Clojure(Script) OSS projects are perfectly good candidates for GSoC

dnolen15:02:55

also there’s a growing #C0N1QHE3W channel for anyone who is interested in either applying as a student or mentor

pandeiro16:02:55

How do you guys typically test for whether something is an HTML element or a CLJS data structure?

mihaelkonjevic16:02:06

I was using this

pandeiro16:02:37

@mihaelkonjevic: Thanks! Is there a reason one couldn't just check for the existence of the nodeType property itself?

mihaelkonjevic16:02:54

you probably could simple_smile

pandeiro16:02:16

Thanks, I like that approach

jaredly16:02:37

@pandeiro: perhaps a more robust approach would be to test whether it’s an instance of js/HTMLElement. e.g. (instance? js/HTMLElement my-thing)

pandeiro16:02:37

@jaredly: yeah that does read more obviously in the code as well, thanks

dnolen17:02:44

@pandeiro: I’m pretty sure there is a goog.dom.isElement predicate

pandeiro17:02:49

@dnolen: there is; that's even better, thanks

pandeiro17:02:18

In this case I could've found that but in general discoverability is an issue with the GClosure stuff

pandeiro17:02:00

Often times I find things by searching for the jquery analog and appending 'google closure' - there are lots of questions on SO in that mold

dnolen17:02:35

@pandeiro: I just look at the Closure docs

dnolen17:02:56

it’s pretty well organized and if you keep poking at it it’s pretty easy to find your way around

pandeiro17:02:59

@dnolen: the issue for me is with so many namespaces, it's not always clear which docs

pandeiro17:02:04

it can be a lot of poking

dnolen17:02:16

@pandeiro: yes there’s a lot of stuff

dnolen17:02:24

but for dom styles etc. it’s pretty clear

pandeiro17:02:25

e.g., I needed the equivalent of $(el).offset() -- where would that live?

pandeiro17:02:32

in that case, it's styles

dnolen17:02:38

yes or styles

dnolen17:02:48

you only have 2 options simple_smile

pandeiro17:02:02

heh, you're right, those two should be bookmarked for sure and searched first simple_smile

virmundi20:02:41

hello. I'm trying to complete work on a chrome extension. If I have optimizations :whitespace, it works fine. When I move to advanced, the plug in fails. The way Chrome invokes the clojurescript is nagsalot.settings.init(); where the first two sections are ns paths.

virmundi20:02:59

Chrome complains that it can't find nagsalot.settings.init();

mfikes20:02:58

@virmundi: Read up on externs

mfikes21:02:20

@virmundi: Actually, you can just mark the fn using ^:extern and :advanced should leave it alone

mfikes21:02:04

@virmundi: Sorry, meant ^:export

virmundi21:02:49

so I do this for my methods?

virmundi21:02:53

my functions?

pdlug21:02:56

Is there a way to handle JS modules like webpack does? Including a CommonJS or ES6 module (ideally via npm) and requiring it from clojurescript?

dnolen21:02:34

@pdlug: if you want to use something from npm not really

dnolen21:02:48

you’ll want to build those deps via some other thing first

pdlug21:02:39

so run browserify, webpack, or some crazy gulp stuff and spit out a combined file that the clojurescript can reference in some way?

mfikes21:02:03

@virmundi: It goes on the function you want to be “exported” (and thus not manipulated during :advanced), like this https://github.com/clojure/clojurescript/blob/c72e9c52156b3b348aa66857830c2ed1f0179e8c/src/test/cljs/hello.cljs#L2

dnolen21:02:15

@pdlug: however note that you will need externs for pretty much anything you’ll want to use - so this is not really ideal for client side applications

dnolen21:02:22

if you’re just targeting Node.js then no big deal

pdlug21:02:51

@dnolen: thanks, we thought that was the case but weren’t sure if we were missing something obvious, using this all client side

dnolen21:02:30

@pdlug: yes then more challenging - none of that stuff can benefit from Google Closure advanced optimizations

mfikes21:02:05

@virmundi: If you happen to have a copy of ClojureScript: Up and Running, ^:export is detailed on pg. 68

virmundi21:02:09

I probably should get that book. Right now I've just taken what I've used in Clojure into Clojurescript. I assumed the advanced was wiping out stuff. I've used gulp for on Angular projects.

mfikes21:02:42

@virmundi: If you don’t have the book and are thinking of getting it, pre-order the new one that is about to come out.

darwin21:02:45

@virmundi: writing and maintaining externs file for chrome extension apis would be quite laborious task IMO, in chromex I’m using string names: https://github.com/binaryage/chromex/#advanced-mode-compilation

kmandrup22:02:55

@mfikes, a new one coming out soon? Nice simple_smile

kmandrup22:02:56

A lot of the books on ClojureScript seem to be a bit dated at this point... tech is advancing too fast!

mfikes22:02:02

@kmandrup: Amazon is saying June 25 simple_smile

mfikes22:02:37

I’m actually surprised a times that the stuff in the original ClojureScript: Up and Running still applies.

kmandrup23:02:12

Sounds good... I've been wanting to write a book on Native app dev using ClojureScript, Datascript/Datomic and React (Native) + Electron (Atom). Lot's to learn!

kmandrup23:02:16

Does ClojureScript: Up and Running also come in ebook format as Early Access?

mfikes23:02:51

@kmandrup: There’s probably lots of good book material on that subject brewing in #C0E1SN0NM

kmandrup23:02:55

Ah, thanks @mfikes simple_smile You're the man in that area for sure!

mfikes23:02:25

Hah, there’s more that I don’t know than what I do know. simple_smile