This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-28
Channels
- # arachne (2)
- # aws (5)
- # aws-lambda (5)
- # beginners (4)
- # boot (25)
- # cljs-dev (270)
- # cljsjs (1)
- # cljsrn (72)
- # clojars (5)
- # clojure (201)
- # clojure-belgium (5)
- # clojure-brasil (4)
- # clojure-italy (2)
- # clojure-korea (2)
- # clojure-russia (24)
- # clojure-spec (24)
- # clojure-uk (22)
- # clojurebridge (1)
- # clojurescript (125)
- # cloverage (3)
- # cursive (41)
- # datomic (37)
- # dirac (4)
- # emacs (2)
- # hoplon (421)
- # lein-figwheel (1)
- # leiningen (5)
- # luminus (2)
- # mount (1)
- # off-topic (18)
- # om (44)
- # om-next (4)
- # onyx (44)
- # pedestal (3)
- # proton (9)
- # re-frame (21)
- # reagent (21)
- # ring-swagger (12)
- # specter (9)
- # sql (2)
- # untangled (62)
- # vim (16)
Is there a way to get a multimethod to dispatch on the type of an object? Just dispatching on type
of an object does not work because a list could be a IndexedSeq
, LazySeq
, or List
.
This works in Clojure but not Clojurescript
(defmulti my-multi #?(:clj class
:cljs type))
(defmethod my-multi #?(:clj ISeq
:cljs cljs.core/List)
[x]
;; handle Lists here
)
Hi, I'm utilizing a button component that only supports href (and not on-click). What is the proper way to execute arbitrary ClojureScript function in the href attribute value?
Oops, nevermind. Undocumented [and uncoded actually] (and thus probably default) support for on-click apparently does exist.
FWIW, to solve my earlier multimethod problem, I just wrote a new type
function:
(defn type->kw
[x]
(cond
(seq? x) ::seq
(vector? x) ::vec
(map? x) ::map
(or (string? x) (number? x)) ::string
:else (type x)))
@kenny @jrheard here is a live demo of the code http://app.klipse.tech/?cljs_in=(defn%20type-%3Ekw%0A%20%20%5Bx%5D%0A%20%20(cond%0A%20%20%20%20(seq%3F%20x)%20%3A%3Aseq%0A%20%20%20%20(vector%3F%20x)%20%3A%3Avec%0A%20%20%20%20(map%3F%20x)%20%3A%3Amap%0A%20%20%20%20(or%20(string%3F%20x)%20(number%3F%20x))%20%3A%3Astring%0A%20%20%20%20%3Aelse%20(type%20x)))%0A%0A%0A(defmulti%20my-multi%20type-%3Ekw)%0A%0A(defmethod%20my-multi%20%3A%3Aseq%20%0A%20%20%5Bx%5D%0A%20%20(first%20x))%0A%0A(defmethod%20my-multi%20%3A%3Avec%20%0A%20%20%5Bx%5D%0A%20%20(second%20x))%0A%0A%0A%5B(my-multi%20%27(10%202%203))%0A%20(my-multi%20%5B10%202%203%5D)%5D
hello. Trying to compile https://github.com/danielsz/system-websockets but getting an error:
@juhoteperi Do you have any idea why the Websocket REPL error :occupied
error would occur in React Native only on Android but not on iOS when using boot-cljs-repl
? Possibly related to Weasel?
@vikeri No idea
Apologies if this is the wrong channel. Iām trying to get a simple ajax call going from my webapp, and itās been a character-developing couple of days. I do not feel like a smart man.
(try
(ajax/POST "/api/loginā ;; ajax is the cljs-ajax library
{:headers {"Authorization" (encode-auth (string/trim id) password)}
:handler #(do
(prn "Success" %)
;; (session/put! :identity id)
;; (js/setTimeout session-timer timeout-ms)
;; (reset! fields nil)
;; (set! (.-href js/location) "#/dashboard")
)
:params {} ;; same symptoms whether this is present or absent
:error-handler #(prn "Failed" %)
})
(catch js/Object e
(log "Caught " e "\n" (.-stack e))
)
Apologies for the commented lines - Iāve stripped it down to the most basic success handler, just a prn
The :params key was added as an experiment, the symptom is the same with or without.
2016-09-28 05:08:06,111 [XNIO-1 I/O-2] DEBUG - Error reading request
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method) ~[na:1.8.0_60]
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39) ~[na:1.8.0_60]
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) ~[na:1.8.0_60]
at sun.nio.ch.IOUtil.read(IOUtil.java:192) ~[na:1.8.0_60]
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380) ~[na:1.8.0_60]
at org.xnio.nio.NioSocketConduit.read(NioSocketConduit.java:286) [xnio-nio-3.3.6.Final.jar:3.3.6.Final]
at org.xnio.conduits.ConduitStreamSourceChannel.read(ConduitStreamSourceChannel.java:127) ~[xnio-api-3.3.6.Final.jar:3.3.6.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:153) ~[undertow-core-1.3.23.Final.jar:1.3.23.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:131) ~[undertow-core-1.3.23.Final.jar:1.3.23.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:57) ~[undertow-core-1.3.23.Final.jar:1.3.23.Final]
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) ~[xnio-api-3.3.6.Final.jar:3.3.6.Final]
at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66) ~[xnio-api-3.3.6.Final.jar:3.3.6.Final]
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:88) [xnio-nio-3.3.6.Final.jar:3.3.6.Final]
at org.xnio.nio.WorkerThread.run(WorkerThread.java:559) [xnio-nio-3.3.6.Final.jar:3.3.6.Final]
But when I issue the same call with curl instead of the web client, it works fine (the curl text was obtained by looking at the failed call in Chrome Dev Tools and ācopying to curlā, so it should be the same as the XHR call from the browser)
~/dev/cavalry-admin # curl '' -H 'Accept: application/transit+json' -H 'Referer: ?' -H 'Origin: ' -H 'x-csrf-token: APvC0olHJjLRz61TKRRIdQlSE4sEloCdE3yCuBwuad9rt9F9Uxdmvh9cv5e5oLL4emN5IkwxyKTZJycW' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36' -H 'Authorization: Basic cm9kZnJleTp0d2VlZGxl' -H 'Content-Type: application/transit+json; charset=UTF-8' --data-binary $'["~#\'",null]' --compressed
["^ ","~:result","~:okā]
I really donāt know what the next step is - this is such a baby step (issue an XHR call from the browser) that Iām not able to accomplish, despite following a recipe.
@juhoteperi Alright Iām investigating to see if I find someting
The chrome inspector allows you to inspect the ws in the network tab
@credulous How'd you setup your server? Did you use a template or anything like that? Or are you experienced enough with clojure to know for sure that that part should be working š
trying to use danielsz/system (ripped apart the example Sente project), and I keep getting this error: java.lang.Exception: #'namen.systems/dev-system is not a SystemMap
@dimovich could you paste your namen.systems/dev-system
var?
@dimovich right so the problem is that youāre using defn
try to use (def dev-system ...)
(obviously removing the argument vector etc)
hrm actually that might not be right
@dimovich hrm, youāre using Boot, right?
could you show me the call to the system
task?
@dimovich thatās just weird, Iāve got a very similar configuration which works perfectly
did you (require ā[namen.systems :refer [dev-system]])
in your build.boot
?
i took this project template https://github.com/danielsz/system-websockets, which compiles fine, and deleted everything I didn't need...
@anmonteiro thx for your help... will try again from scratch š
@kauko I used Luminus. Iām pretty sure itās working because I have logging statements throughout the server code and I get positive logs right up until the return value of the last handler. Also, when I call the server using curl it works fine.
I guess you could try creating a fresh luminus project and try to see where you've done something different? IIRC the template includes some ajax calls
Hi. I'm working with the Google Maps API places autocomplete search box and I need to select the first entry on Enter or Tab. I saw some answers on StackOverflow that involve wrapping the listener and simulating a down arrow press on enter or tab. Here's the code I have so far http://pastebin.com/Ex6Zu48q can someone guide me on how I can wrap the event listener and simulate a down arrow press?
@viebel - one question iāve had re: using klipse in blog posts - is there a way to include third-party libraries? like, say i want to have a blog post that plays around with core.logic
seems like a tall order, iām not sure how one would go about implementing it, but i figured iād check just in case š
@jrheard there is a way to use third-party libraries using data-external-libs
. See https://github.com/viebel/klipse#clojure-only-1
But there is a catch: the library must be self-hosted cljs compatible
Check this blog post for instance: http://blog.klipse.tech/lambda/2016/07/24/lambda-calculus-2.html
one other thing hasnāt been obvious to me - how is it that klipse windows later on in the document are able to access definitions from earlier on in the document?
Where Iām requiring a library of mine named gadjett
eg in one window you define a record Foo, and later on you use Foo, and the second window still works even if i change Fooās definition in the first
@jrheard all the evaluations occur in the same context
makes sense?
are you saying that on pageload, each window is evaluated one after the other, and is able to access definitions from earlier windows?
(iām using the word āwindowā here because i donāt know what word to use for ākilpse plugin instanceā or whatever) š
the proper word is: āsnippet"
Youāre right about evaluation order of the snippets
but theyāre not, like, permanently linked - so after pageload happens, if i modify or remove the definition of T in http://blog.klipse.tech/lambda/2016/07/24/lambda-calculus-2.html , later windows arenāt affected, and thatās expected+good, right?
100% correct
until you re-evalute the other snippets
with Ctrl-Enter
then the new definitions will affect the snippets
ah, yeah, for some reason i thought that that wasnāt the case, but i see that it works now
i think what i was doing was just removing definitions and ctrl-entering them, and of course that wouldnāt affect the rest of the document
BTW, are you planning to write a blog post with klipse snippets?
youāll be the first to know when i do š i know youāre trying to get a lot of publicity for this tool and it makes a ton of sense
but hopefully in the next month or two iāll crank something out, and iāll definitely let you know
fwiw i learned about it by watching one of your talks on youtube, probably from strange loop
It was clojutre https://www.youtube.com/watch?v=33mTFjPIN10&feature=youtu.be
I am so enjoying writing the blog posts
I want the community to engage
you can call it publicity
when using the bootstrap compiler, evaluating "(ns foo.bar) [1 2 3]"
;=> [1 2 3]
but evaluating "(ns foo.bar) 42"
;=> nil. Is this correct?
trying to respond to an ajax GET with a clojure data structure, but client receives ""...
ok.. Cheshire seems to work on server side, and on client {:response-format (cljs-ajax/json-response-format) seems to do the trick
Does anyone know how to simulate a key press event using closure?
Google Closure
@andres-alonso: donāt know about closure library, but this is what I use for my tests: https://github.com/eventualbuddha/keysim.js
@darwin thanks!
@pat the evaluation of 42
to nil
is related to the evaluation context. See: https://github.com/viebel/klipse#clojure-only-1
@pat expectations about the top level are unrealistic given weāre compiling to JS source files
absolutely no guarantee that the value of the last form in a ns that looks like that is returnable
and itās perfectly fine that the REPL and the compiler might not even correspond here
@dnolen what about without a ns form? (eval-str "42") ;=> nil
. My use case is simple scripts
if youāre interested in fixing that then the right place for this conversation is in #cljs-dev
iāve found myself in a situation where i have ~7 lines iād like to add to each of my :cljsbuild :builds in my project.clj: https://github.com/jrheard/voke/blob/commonjs/project.clj#L34-L40
i read through https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md , but it doesnāt seem like i can use leiningen profiles to accomplish this
i feel like there must be some sane + standard way of doing this sort of thing, so i figured iād check with the channel. thanks!
@jrheard you can put them in a deps.cljs
file in your classpath