This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-19
Channels
- # beginners (25)
- # boot (143)
- # braid-chat (9)
- # cider (18)
- # cljs-dev (88)
- # cljsrn (1)
- # clojure (91)
- # clojure-austin (2)
- # clojure-berlin (3)
- # clojure-japan (26)
- # clojure-russia (148)
- # clojurebridge (1)
- # clojured (29)
- # clojurescript (105)
- # cursive (7)
- # data-science (4)
- # datomic (15)
- # devcards (4)
- # emacs (8)
- # euroclojure (2)
- # events (1)
- # gsoc (27)
- # hoplon (3)
- # immutant (3)
- # ldnclj (3)
- # lein-figwheel (9)
- # leiningen (2)
- # luminus (1)
- # off-topic (5)
- # om (176)
- # onyx (136)
- # parinfer (16)
- # proton (13)
- # re-frame (33)
- # reagent (34)
- # spacemacs (1)
- # yada (127)
This is strange
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.
@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
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.
thanks a lot guys! this will really help me
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.
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
should I use requestAnimationFrame?
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
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.
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
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)})]
I just have a simple button though that's not attached to any form, would i have to convert all to a form?
[:button {:on-key-down #(when (= (. -which %) 13) do-the-thing)}]
[: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
first replace (auth/login! @username @password) with (.log js/console “i was clicked”)
click the button and check if anything gets logged
but also on key down wont realaly work on the button
unless it is being focused
I think what you really want to do is attach that to the input which is being used
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
ohhhh that makes sense.
Thank you
yeah ignore my above code
idk why i wronte [:button
that makes no sense
[:button {:on-click #(.log js/console “i was clicked”)}]
that worked by the way ("i was clicked")
[:input {:on-key-down #(when (= (. -keyCode %) 13) (.log js/console “enter was typed”))}]
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
and finally you could set the value of the input to always reflect the value of the model
yeah I already do that
There we go, thanks for your help
Trying to improve the ClojureScript wiki, https://github.com/clojure/clojurescript/wiki/Working-with-Javascript-classes
I've seen many developers stumble on this, including myself... feel free to contribute and correct.
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?but (js->clj #js {"hi" "there"} :keywordize-keys true)
returns {:hi "there”}
@petrus Maybe because the entire thing isn’t a JS object? How about if you did this? #js [#js {"hi" "there”}]
if you’re a student a reminder to submit GSoC project ideas http://dev.clojure.org/display/community/Project+Ideas+2016
for examples of previous project ideas http://dev.clojure.org/display/community/Project+Ideas+2015
also if you’re interested in being a mentor you can propose an idea you would like to mentor
also there’s a growing #C0N1QHE3W channel for anyone who is interested in either applying as a student or mentor
How do you guys typically test for whether something is an HTML element or a CLJS data structure?
I was using this
@mihaelkonjevic: Thanks! Is there a reason one couldn't just check for the existence of the nodeType
property itself?
you probably could
@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)
In this case I could've found that but in general discoverability is an issue with the GClosure stuff
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
it’s pretty well organized and if you keep poking at it it’s pretty easy to find your way around
@dnolen: the issue for me is with so many namespaces, it's not always clear which docs
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.
@virmundi: Actually, you can just mark the fn using ^:extern
and :advanced
should leave it alone
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?
so run browserify, webpack, or some crazy gulp stuff and spit out a combined file that the clojurescript can reference in some way?
@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
@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
@dnolen: thanks, we thought that was the case but weren’t sure if we were missing something obvious, using this all client side
@pdlug: yes then more challenging - none of that stuff can benefit from Google Closure advanced optimizations
@virmundi: If you happen to have a copy of ClojureScript: Up and Running, ^:export
is detailed on pg. 68
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.
@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.
@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
A lot of the books on ClojureScript seem to be a bit dated at this point... tech is advancing too fast!
I’m actually surprised a times that the stuff in the original ClojureScript: Up and Running still applies.
http://www.amazon.com/ClojureScript-Running-Functional-Programming-Web/dp/1491924993
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!
Doesn't look like it: http://shop.oreilly.com/product/0636920039525.do