This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-27
Channels
- # adventofcode (1)
- # announcements (4)
- # beginners (120)
- # calva (5)
- # cider (12)
- # clara (3)
- # cljdoc (48)
- # cljs-dev (33)
- # cljsrn (4)
- # clojure (124)
- # clojure-dev (43)
- # clojure-europe (2)
- # clojure-italy (168)
- # clojure-nl (2)
- # clojure-spec (7)
- # clojure-uk (79)
- # clojurescript (50)
- # core-logic (6)
- # cursive (12)
- # datascript (1)
- # datomic (8)
- # devcards (2)
- # emacs (5)
- # events (2)
- # figwheel-main (6)
- # fulcro (18)
- # graphql (42)
- # hyperfiddle (3)
- # jobs (1)
- # luminus (2)
- # nrepl (5)
- # off-topic (59)
- # onyx (5)
- # parinfer (2)
- # pathom (10)
- # pedestal (2)
- # portkey (3)
- # re-frame (24)
- # reagent (6)
- # reitit (54)
- # remote-jobs (1)
- # ring (5)
- # shadow-cljs (75)
- # spacemacs (35)
- # sql (22)
- # tools-deps (16)
- # unrepl (10)
What am I missing? I just tried to put my own client.js file into my index.html and although it loads the file, goog is not defined ;_;
could it have something to do with this? https://gist.github.com/swannodette/8775213 - tldr; try setting a different :optimizations level (eg. :whitespace) in your :cljsbuild options in project.clj
Hey guys, has anyone in here ever published a CLJS app to github pages? If so, how? Im using shadow-cljs btw
@vitorstipanich i've never tried that but it seems possible, if your app is just html and js...
@sova yeah thats what I thought. but how to generate a ‘production’ js? with the dependencies and stuff
@vitorstipanich perhaps: https://github.com/thheller/shadow-cljs/wiki/Production-Builds could be helpful?
that helped me. and also I compiled the production build with both js and html on the same directory
Yay!!!!
I was finally able to write a working project.clj that has two javascript files as outputs
and now, instead of "hello world," my app says, "The world is yours."
Hey guys, i am building a restful api with compojure-api and using swagger. i have to return a vector of vector as result a http request but i can figure out achieve that with swagger. Can anyone help me please?
I just sent it @trailcapital ☝️
is vector
a schema to be applied against the body or is it the clojure.core/vector
function?
You can use https://github.com/plumatic/schema to define a schema for the response
right, it will allow anything to be included inside the vectors. I'm not sure what your response looks like so I can't scope it down more - but yeah, you can't pass a function as the value for :return
- it needs to be a schema which validates the response
@trailcapital please check this code from swagger dataytpes
I'm not an expert on Plumatic's schema by any means, but from my understanding, if you have an object that is not a clojure type then you can define you're own spec by making sure the object is of a certain class. i.e.
(s/validate java.lang.String "schema")
I would read through the https://github.com/plumatic/schema README. That's where I got the above example from.
there is no s/Vector, but it would be easy enough to define one yourself (and an equivalent for other missing types):
(def Vector [s/Any])
I'm not sure how practical that is - there may be a reason that s/Vector doesn't already exist.that is what i am suspecting or like you said it's one of those datatype that user should create
I thought sequences are compared by value.
(= [1 2] '(1 2))
evaluates to true
but (= [1 2] #{1 2})
evaluates to false
.
What am I missing here?
(= [1 2] (seq #{1 2}))
is true
and so is (= [1 2] (first {1 2}))
.
I'm confused 😕
What's the difference b/w clojure.lang.ISeq
and clojure.lang.Sequential
?
ISeq is for sequences, Sequential is a more generic trait for any sequential thing (lists, vectors, sequences, etc)
@jaihindh.reddy (seq #{:a :b :c :d :e})
is stable but that doesn't mean you can predict what it will be. so in your example it happens to be (1 2)
but that is not true in general
@quieterkali [[s/Int]]
would be a "array of integer arrays".
@ikitommi thanks for your answer. so if i have a cusotm object, then it will be [[s/customobject]] 🙂
Equality of collections uses an equality “partition” of comparable collection types: sequentials, sets, and maps
Collections don’t compare equal across the partitions but do within each partition
Is there a way to express the following in a more succinct manner:
(when (and (contains? params :upsert) (= (params :upsert) true)) "... ... ...")
I keep using the pattern (first (filter predicate? items))
and then doing something with the result. Is there some some
variation that would be better?
defining ffilter
as (def ffilter (comp first filter))
is quite common I think. Don't think there's a more succinct way built in
alternative suggestions ive seen are using a different data structure to store your data, eg a hashmap. which may not be helpful all the time but sometimes i refactor (first (filter ...))
s to
@U051H1KL1 @U0C7D2H1U thanks guys!
^^^ Makes sense. But what are the semantics of ISeq
and Sequential
. Why doesn't clojure.lang.PersistentHashSet
implement Sequential
?
sets are unordered
and thus have no canonical sequential ordering
Hello, does anyone have a recommendation of a clojure library for mocking http server?
@tvanish do you mean you want to mock out sending requests and receiving responses, as if with an http server?
Yes, my code should call http server and get some response. I want to mock the behaviour of the server from the test and assured that it did get my request
You could use http-kit or similar to just build a real http server like hiredman suggested, but it may be sufficient to just test the code to make sure it’s sending the right request maps, and responding correctly to mock response maps.
POST works great, puts the params in the message body (???) so :params {} on the server is empty and :body is #object[IncomingMessage [object Object]]
how can I parse out the :params {} map on the server?
CLJS params empty when using cljs-ajax o.O
well, [object Object]
is the default toString of any plain old javascript object
Okay, that helps. I guess the info I want must be cryptically tucked into :body
probably yeah
but I know bare to nothing about cljs, so I cant help you any further
no problem, thanks for the tip
Hmm what to do with #object[IncomingMessage [object Object]]
@sova for things like that in cljs my usual technique is to use the console.log method to inspect in the browser, which should expose the full class name and the methods and slots
then if you are lucky it's a stock js type so there's an MDN page for it
Thank you @noisesmith i rearranged the sequence of some keys in the map I was trying to POST and things began working.
namely, I had to move all my params straight into the :body {} and send the :headers with x-csrf-token a-f-t last. probably due to some sort of pre-emptive packet creating
Can anyone give me a hint as to how to add meta to a js/Error
? I called (with-meta (js/Error "message") {:x :y})
, but got "No protocol method IWithMeta.-with-meta defined for type object: Error: message". I assume I could just extend IWithMeta, but would I just stick it on the object using a plain old javascript property?
Think I got it:
(extend-protocol IWithMeta
js/Error
(-with-meta [e meta] (aset e "meta" meta) e))
(extend-protocol IMeta
js/Error
(-meta [e] (aget e "meta"))
(meta (with-meta (js/Error. "message") {:x :y}))
;; => {:x :y}
it is not IMeta
but it doesn’t need to be because it takes data
which can be IMeta
if you like
What’s the fastest way to convert a hash-map to a list of vector pairs? I got (map identity {:a 1 :b 2 :c 3})
is there a better function for that?
Tools like criterium
are your friend for determining what is fastest, in the absence of other information, but I'd guess seq
would be somewhat faster than what you proposed.
Heh wow seq will definitely work. I’ll check out criterium now too. It will not be a lot of maps or even a very big map.
What's an idiomatic way to run an infinite go-loop until the initiating thread says to stop?
Looks like I can use alts!. I think this will produce to produce-ch until a value is provided on stop-ch. Is this the right track?
https://github.com/hiredman/roundabout/blob/master/src/com/manigfeald/roundabout.cljc#L50 is an example of that sort of thing
usually I would write the code to accept stop-ch as an argument - but otherwise you can also skip defining a stop-channel and just exit if someone closes your input or output channel
you should be checking your channel reads and writes for nil anyway, and the natural thing to do is to exit if one gets closed
this is how much of core.async works - you ask something to exit by closing a channel it relies on
The go-loop is going to be an algorithm that produces its own values, rather than processing something off an input-channel, so I think I need a stop-ch since the loop is otherwise independent of the outside world. Is my thinking correct? I suppose I could close the produce-ch when I don't need its values anymore.
putting to a closed channel returns nil
right - if you use a channel to read or write, you should probably check for nil and exit, so the stop behavior is already there in the correct error handling behavior
(there are more complex cases of course if you don't rely on any one specific input or output chan...)
Makes sense, thanks!
Anyone have tips on building a map using something like reverse :keys
destructuring (ala javascript)? I know I could write a macro, just wondering if something exists. E.g.:
(let [one 1 two 2]
(succinct-map one two))
;; => {:one 1 :two 2}
(defrecord Node [elm left right]) (Node. 1 3 5) => #cljs.user.Node{:elm 1, :left 3, :right 5}
it came up here: https://clojureverse.org/t/shortand-clojure-syntax-for-properties-on-hashmaps/1918 TL;DR. many people hate it for some reason. i think it is great. three's a macro in the comments
that succinct-map or whatever you want to call it is a great thing for debugging even if you consider it bad style in committed code