This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-18
Channels
- # admin-announcements (1)
- # aleph (3)
- # beginners (20)
- # boot (9)
- # cider (74)
- # clara (1)
- # cljs-dev (28)
- # cljsrn (15)
- # clojars (32)
- # clojure (149)
- # clojure-dusseldorf (3)
- # clojure-italy (6)
- # clojure-nl (3)
- # clojure-russia (20)
- # clojure-uk (5)
- # clojurescript (133)
- # core-async (2)
- # cursive (19)
- # datomic (24)
- # devcards (1)
- # funcool (100)
- # hoplon (48)
- # keechma (1)
- # kosmos (7)
- # ldnclj (3)
- # leiningen (3)
- # luminus (16)
- # off-topic (8)
- # om (103)
- # onyx (47)
- # pedestal (3)
- # proton (7)
- # re-frame (13)
- # reagent (11)
- # ring-swagger (1)
- # specter (6)
- # testing (12)
- # untangled (24)
- # yada (32)
I have a protocol that I'm trying to to implement for all seqable collections (basically, just vectors and lists for my purposes). I have observed that (extend-type PersistentVector ..)
extends vectors, and (extend-type List)
extends lists. But how do I extend both of these items in one extend-type
declaration?
@george.w.singer: you could use extend-protocol
https://clojuredocs.org/clojure.core/extend-protocol
That works
Although my implementation for PersistentVector and List is literally -- word for word -- the same
So with extend-protocol
I'm copy and pasting the same function for each PersistentVector
and List
is that the best way to go about it?
You could extract the content to another function, and just call them in each implementation in extend-protocol
. I'm not sure that there is any way to do one implementation for n types, though
Ok cool
also a macro could help whenever you find yourself mechanically copy&pasting top-level code
what about extending ISeq instead?
or is that possible...
Declare a map with common impl {:function-name (fn...}
and later use that map in extend
for each type you want
Iām trying to use the latest material-ui in my project, but seem to get too many errors
material-ui version 14.4: http://www.material-ui.com/#/ react: 0.14.0 (not the latest ) i keep getting the following errors: #object[Error Error: js/ReactDOMServer is missing] #object[Error Error: js/ReactDOM is missing]
I am downloading and compiling the javascript files using ānpmā and ābrowserifyā to put them in one file
ClojureScript 1.8.34 released https://groups.google.com/d/msg/clojure/J2d_WNHrDr4/YPAN4U3VDQAJ
This isnāt hard to work around, but is it expected behavior for #js
in a go
macro not to be able to pick up vars that were bound inside the go
scope?
(defn repositories-req [language] (go (let [response (<! (http/get github-repositories-url {:with-credentials? false :query-params {"q" (str "language:" language) "sort" "stars" "order" "desc"}}))] (repositories-res response))))
@thiagofm: the function is returning a channel (the one from the go block)
which puts the result of (repositories-res response)
on the channel
so I presume somewhere you are doing (<! (repositories-req āclojureā))
If I try doing that, it complains that: #object[Error Error: <! used not in (go ...) block]
if you really wanted to, just move the (<! ā¦)
inside a function you call
yes, because <! must always be in a go block
(<!! ch)
can be used outside a go block
but you donāt have that in cljs
no issue
just put it in a go block
depends on the structure of your code, but you are telling it to do something async
Yes, it makes a request to the github API. As I'm using cljs-http, it uses a channel, but I don't know core.async
With the current setup "it works", but I would like to make it look just a normal function that gives some result that isn't a channel
why do you ājustā want it to look like a function?
Because it makes testing a bit complicated. It basically gives the response to the "repositories-res" function. I don't want to have that
itās the exact opposite of callbacks but letās see if i can help
(go (let [value (<! (repositories-req āclojureā))] (println value))
if you need to, you can put that in a function
@christianromney: this is what I have now: https://github.com/thiagofm/haxlife/blob/master/src/cljs/haxlife/github.cljs
or rather, you can just put the outer go / let inside repositories-req
(go (let [value (<! (repositories-req "clojure"))] value)) ; gives me: #object[cljs.core.async.impl.channels.ManyToManyChannel]
yes but hereās the thing
itās just how youāre thinking about it
this is making an ajax call
forget clojurescript / core.async
if you just make an ajax call using jquery $.get()
it returns immediately
the call to get
you can pass it a callback (weāll get past this in a sec)
for it to invoke when it actually receives a response
in that call back you usually do something
(e.g. modify the DOM or whatever)
this is no different
when you call (go )
itās analogous to the $.get above
you still want to do something when it returns
(to the DOM or whatever)
that is what you do inside the go block that reads from the channel
all core.async does is flatten it out
so you donāt have a callback. the "callback" is inside the body of the go block that reads from the channel
Because this way it looks like a callback. From the go block after I do the get call, I specify the next function, and then the next function could specify the next and so on... and this is a callback hell
sure you can
no need to keep chaining the functions
what do you ultimately do with the returned value?
@thiagofelix: go block returns a channel which yields the value. The consumer of that function needs to take from that channel in a go block as well
thatās what he means by the russian doll thing above
heās asking where do all the goās end?
help me out š
iām not doing a good job
no not at all
no bad studentsā¦only bad teachers
One easy example: (go (let [value (<! (repositories-req "clojure"))] value) value, the second arg to the go block, can't be accessed from outside the go block
the idea is that function should actually do something with the value
is this a React application?
normally what we do inside the go block when we get the value
How does that differ from $("endpoint.json", function (res) { console.log(res); }) ?
is we update an atom
itās subtle
you are not handing a function to http/get
thiagofm channels help decuple the logic of doing something from the source of the events
the caller controls when the value is read
an event fires and then puts the data on a channel, which can either do something with it, or put it onto another channel, or whatever
the channel does not care, or want to care about the source of the data
just for clarity
@christianromney: It's Om next. That part you don't have to worry. I've just wanted to make the req be sincronous
if you are using om next there is already a good story for handling events
thereās the rubāyou canāt really make synchronous requests
have you looked into the transactor
@adamkowalski: not yet, I'm trying to first do it a little bit in the vanilla way and then find a way to use it
(and you wouldnāt want to tie up the ui thread to do it if you could)
the idea is the go blocks do something async and update an atom. UIs react to changes in the atom and re-render
@christianromney: but I can make it look like a sync req by using a promise
there shouldnt be any blocking put or take
you donāt have multiple threads so that wouldnt really make sense