Fork me on GitHub
#clojurescript
<
2016-09-28
>
kenny00:09:46

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.

kenny00:09:08

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
  )

johanatan00:09:04

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?

johanatan00:09:23

Oops, nevermind. Undocumented [and uncoded actually] (and thus probably default) support for on-click apparently does exist.

kenny03:09:26

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)))

kenny05:09:47

Cool! Haven't seen that app yet. Only slightly annoying thing is the URL šŸ˜‰

dimovich07:09:36

hello. Trying to compile https://github.com/danielsz/system-websockets but getting an error:

danielsz08:09:46

@dimovich system-websockets require Clojure 1.8

dimovich08:09:24

added boot.properties to the project with clojure 1.8.0 requirement

dimovich08:09:30

compiles now šŸ™‚

vikeri08:09:52

@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?

credulous09:09:59

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.

credulous09:09:37

The call is for login, and it sends no data - just an authorization header.

credulous09:09:06

(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))
         )

credulous09:09:39

Apologies for the commented lines - Iā€™ve stripped it down to the most basic success handler, just a prn

credulous09:09:17

The :params key was added as an experiment, the symptom is the same with or without.

credulous09:09:41

In any case, when this code is executed, the server seems to choke on request:

credulous09:09:00

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]

credulous09:09:34

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)

credulous09:09:19

~/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ā€]

credulous09:09:38

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.

vikeri09:09:33

@juhoteperi Alright Iā€™m investigating to see if I find someting

vikeri09:09:35

Does anyone now a good way to inspect websockets?

leongrapenthin10:09:28

The chrome inspector allows you to inspect the ws in the network tab

kauko10:09:44

@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 šŸ™‚

dimovich11:09:11

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

dimovich11:09:21

if anyone bumped into this before, let me know plz šŸ™‚

anmonteiro12:09:11

@dimovich could you paste your namen.systems/dev-system var?

anmonteiro12:09:54

@dimovich right so the problem is that youā€™re using defn

anmonteiro12:09:05

try to use (def dev-system ...)

anmonteiro12:09:19

(obviously removing the argument vector etc)

anmonteiro12:09:30

hrm actually that might not be right

anmonteiro12:09:17

@dimovich hrm, youā€™re using Boot, right?

anmonteiro12:09:28

could you show me the call to the system task?

dimovich12:09:28

yeah, def doesn't fix it...

dimovich12:09:40

(system :sys #'dev-system :auto true :files ["handler.clj"])

anmonteiro12:09:22

@dimovich thatā€™s just weird, Iā€™ve got a very similar configuration which works perfectly

anmonteiro12:09:55

did you (require ā€˜[namen.systems :refer [dev-system]]) in your build.boot?

dimovich12:09:08

yes I did...

dimovich12:09:58

i took this project template https://github.com/danielsz/system-websockets, which compiles fine, and deleted everything I didn't need...

dimovich12:09:20

seems I also deleted something I shouldn't had to

dimovich12:09:59

@anmonteiro thx for your help... will try again from scratch šŸ™‚

credulous12:09:54

@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.

kauko13:09:40

Huh.. maybe try asking in the #luminus channel? I'm sorry I can't help you

credulous13:09:12

Yeah tried but the response was that it looked like a server problem. I dunno.

kauko13:09:46

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

andres-alonso14:09:35

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?

jrheard15:09:47

@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

jrheard15:09:53

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 šŸ˜„

dominicm15:09:10

@kenny I feel like you really want extend-protocol instead of multimethod on type.

Yehonathan Sharvit15:09:16

@jrheard there is a way to use third-party libraries using data-external-libs. See https://github.com/viebel/klipse#clojure-only-1

Yehonathan Sharvit15:09:08

But there is a catch: the library must be self-hosted cljs compatible

jrheard15:09:14

aha, makes sense

jrheard15:09:58

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?

Yehonathan Sharvit15:09:03

Where Iā€™m requiring a library of mine named gadjett

jrheard15:09:19

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

Yehonathan Sharvit15:09:22

@jrheard all the evaluations occur in the same context

jrheard15:09:12

not sure i follow, sorry

jrheard15:09:41

are you saying that on pageload, each window is evaluated one after the other, and is able to access definitions from earlier windows?

jrheard15:09:58

(iā€™m using the word ā€œwindowā€ here because i donā€™t know what word to use for ā€œkilpse plugin instanceā€ or whatever) šŸ™‚

Yehonathan Sharvit15:09:24

the proper word is: ā€œsnippet"

jrheard15:09:28

gotcha, makes sense

Yehonathan Sharvit15:09:43

Youā€™re right about evaluation order of the snippets

jrheard15:09:49

cool, makes sense

jrheard15:09:22

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?

jrheard15:09:43

awesome, makes sense

jrheard15:09:55

thanks a bunch for answering my questions! šŸ™‚

Yehonathan Sharvit15:09:59

until you re-evalute the other snippets

Yehonathan Sharvit15:09:27

then the new definitions will affect the snippets

jrheard15:09:42

ah, yeah, for some reason i thought that that wasnā€™t the case, but i see that it works now

jrheard15:09:53

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

Yehonathan Sharvit15:09:54

BTW, are you planning to write a blog post with klipse snippets?

jrheard15:09:31

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

jrheard15:09:37

iā€™ve mainly just been curious, no immediate plans atm

jrheard15:09:46

but hopefully in the next month or two iā€™ll crank something out, and iā€™ll definitely let you know

jrheard15:09:16

fwiw i learned about it by watching one of your talks on youtube, probably from strange loop

jrheard15:09:23

iā€™ve been following the blog since then, good stuff

jrheard15:09:47

ah yeah thatā€™s the one

Yehonathan Sharvit15:09:58

I am so enjoying writing the blog posts

jrheard15:09:02

šŸ˜„ nice

Yehonathan Sharvit15:09:06

I want the community to engage

Yehonathan Sharvit15:09:28

you can call it publicity simple_smile

pat16:09:52

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?

dimovich16:09:27

trying to respond to an ajax GET with a clojure data structure, but client receives ""...

dimovich16:09:46

using cljs-ajax.

dimovich16:09:05

if responding with a string, the client gets everything ok

dimovich16:09:22

using (str {...}) doesn't seem right

dimovich16:09:35

ok.. Cheshire seems to work on server side, and on client {:response-format (cljs-ajax/json-response-format) seems to do the trick

andres-alonso16:09:55

Does anyone know how to simulate a key press event using closure?

andres-alonso16:09:21

Google Closure

darwin16:09:24

@andres-alonso: donā€™t know about closure library, but this is what I use for my tests: https://github.com/eventualbuddha/keysim.js

Yehonathan Sharvit19:09:13

@pat the evaluation of 42 to nil is related to the evaluation context. See: https://github.com/viebel/klipse#clojure-only-1

dnolen19:09:20

@pat expectations about the top level are unrealistic given weā€™re compiling to JS source files

dnolen19:09:02

absolutely no guarantee that the value of the last form in a ns that looks like that is returnable

dnolen19:09:22

and itā€™s perfectly fine that the REPL and the compiler might not even correspond here

pat20:09:35

@dnolen what about without a ns form? (eval-str "42") ;=> nil. My use case is simple scripts

dnolen20:09:58

@pat itā€™s not well supported yet

dnolen20:09:10

there are a few tickets floating around to make it work but itā€™s non-trivial

dnolen20:09:33

also simply - just not a priority - unless someone wants to deliver the patch

pat20:09:43

im looking at emit* for constants, skips when not statement

pat20:09:35

not complaining just want to understand

dnolen20:09:50

itā€™s not supported šŸ™‚ this is the explanation

dnolen20:09:58

and itā€™s not supported because no one has worked on it

dnolen20:09:29

if youā€™re interested in fixing that then the right place for this conversation is in #cljs-dev

jrheard21:09:34

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

jrheard21:09:41

right now iā€™ve just copy-pasted them into each build, but that seems gross and bad

jrheard21:09:54

is there a saner way of saying: always have these :foreign-libs in every build?

jrheard21:09:08

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

jrheard21:09:28

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!

anmonteiro21:09:20

@jrheard you can put them in a deps.cljs file in your classpath

jrheard21:09:38

huh! neat! are the semantics of this deps.cljs file documented somewhere? now that iā€™m googling for it, i see it referred to in a few pages on how to package libraries for consumption, but iā€™m building an app and this feature looks useful in this context as well