This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-17
Channels
- # aws (10)
- # beginners (64)
- # boot (3)
- # cider (20)
- # cljs-dev (32)
- # cljsrn (6)
- # clojure (126)
- # clojure-dusseldorf (3)
- # clojure-finland (1)
- # clojure-greece (1)
- # clojure-italy (7)
- # clojure-poland (3)
- # clojure-spec (46)
- # clojure-uk (100)
- # clojurescript (37)
- # cursive (11)
- # datomic (6)
- # defnpodcast (2)
- # emacs (1)
- # events (3)
- # figwheel (2)
- # fulcro (20)
- # immutant (2)
- # jobs (1)
- # jobs-discuss (9)
- # keechma (3)
- # lein-figwheel (1)
- # luminus (2)
- # lumo (3)
- # mount (2)
- # off-topic (19)
- # om (3)
- # om-next (2)
- # onyx (20)
- # other-languages (55)
- # parinfer (11)
- # pedestal (8)
- # portkey (3)
- # protorepl (3)
- # re-frame (22)
- # ring (9)
- # rum (1)
- # shadow-cljs (82)
- # spacemacs (28)
- # sql (15)
- # test-check (15)
- # testing (2)
- # tools-deps (102)
- # vim (26)
@gcast Thanks for the answer! Seems like at this point using transducer is just better overall(?), advantages of dealing with small number of items seems negligible to me.
Assuming this is a Clojure-on-Java project (not ClojureScript), maybe Eastwood might be able to help you find namespace/file weirdness in your project. No promises. This advice may be worth more than you paid for it, but maybe not.
ns-tracker would certainly be more helpful if it reported the cycle of dependencies that it found.
Well now that that's through, how can I write a spec for a map that will only take certain keys?
For example I want
{:a .. :b ..}
to be valid, but not {:a .. :b .. :c}
You could use “keys” and “and” with another predicate to enforce that. But spec is generally designed to discourage that practice
hi - is it possible to return something like the entire path from a bidi match? (Ignoring params for a moment) It seems like the return is always {:handler :some-kw}
- I could do some lookup to "unconvert" it, but is there some way to return arbitrary data from a bidi match? thanks to anyone in advance
I'm not able to find a way how to redirect a user to another page using ClojureScript + secretary library. E.g. I have a login page in url "http://localhost:3445/#/login". Once the login is successful I'd like the user automatically get redirected to the next page, e.g. "http://localhost:3445/#/productgroups". If I call "(secretary/dispatch! "/productgroups")" in the login page's handler this will render the productgroups page, but the page url still stays on "http://localhost:3445/#/login". Maybe I'm missing something simple since I'm learning frontend development and SPA.
Rubber duck effect seems to be working again. Once I wrote the question I was wondering whether I should do the new location using Javascript. I added in login page's handler: "(set! (.-location js/document) "/#/productgroups")" and it did the trick. I guess this is the righ way to redirect the user to the next page in SPA?
@kari.marttila This looks like it should be handled by the library. I use bidi with pushy and the uri is set automatically for me.
Anyone ever feel like they regress in skill a little bit? I wrote clojure every day for months and I made an entire imgur-esque website to host my personal image uploads in a few days, I got distracted by life for a few months and 400 lines takes me a week. I have to get everything refreshed in my head @_@
I imagine spec would be the first to forget, followed by the order of the arguments to the map-indexed
function (was it [item index] or [index itm]? 🙂 )
Thats just normal, I have been writing java for almost 10 years now and still have to lookup stuff that would seem common knowledge, but if you never use it and are unsure 😄
I just realized that if I create a SPA using ClojureScript and Reagent + Secretary and use r/atom for app-state and store the current page and JSON Web Token in the app-state, a refresh in any page resets the app-state. This is a bit of a nuisance since the user needs to login again to get a valid JSON Web Token. Is there any way to handle this in ClojureScript/Reagent/Secretary or should I store the JSON Web Token in browser's local / session storage?
@kari.marttila you would need to store it in localstorage anyway to persist between closing the browser tab. Unless you want your user to login all the time anyway.
don't store JWT in local storage
> When storing your JWT in a cookie, it's no different from any other session identifier. But when you're storing your JWT elsewhere, you are now vulnerable to a new class of attacks (...)
disclaimer: I'm actually doing this in my own app for now. it's still terrible and I should fix it
@sveri and @joelsanchez: thanks for hints. I'm just learning ClojureScript and creating a demo SPA for learning purposes so I'm not that worried about to make the demo app 100% secure. I'll store the session to local storage for now.
There are lengthy discussions about this topic and everything has pro and cons. You need to secure your app against XSS attacks and transport everything over https if you store it in localstorage. On the other hand, storing it on server side you need to make sure you are safe of CRFS attacks.
not really a tutorial but an enjoyable article: http://www.flyingmachinestudios.com/programming/datomic-for-five-year-olds/
I collected some links and videos on my pinboard https://pinboard.in/u:ghadi/t:datomic
there are the Day of Datomic videos at https://vimeo.com/cognitect too
This is baffling me, so gonna ask you guys.
So far I cant’ find on google for a Clojurescript implementation of a Live Chat
Been looking after Clojurescript "live chat"
with no luck
What’s the reason for preferring
`(:identity ~'foo-map))
over
`(:identity foo-map)
It’s used in a compojure-api example here: https://github.com/metosin/compojure-api/wiki/Creating-your-own-metadata-handlers
(defmethod compojure.api.meta/restructure-param :roles [_ roles acc]
(update-in acc [:lets] into ['_ `(require-role! ~roles (:roles ~'+compojure-api-request+))]))
foo-map
will resolve the symbol foo-map in the context of the current namespace, returning a namespaced symbol.
~'foo-map
will quote, then evaluate, returning the bare un-namespaced symbol.
@alexmiller right, so you want the un-namespaced variant if, for example, you’re quoting a symbol that will be evaluated in another ns where that symbol is already defined?
I presume so
I didn’t read all the context
I think in the compojure example, into’s param will be later expanded within a macro, so that would make sense.
So, are :pre and :post conditions worth using? If I want to validate input and output of a function and return descriptive errors in that kind of manner can I use spec? What's the deal here
@alice the spec guide covers this: https://clojure.org/guides/spec#_using_spec_for_validation
Is there an idiomatic way to do (rest [1])
, so that it returns []
instead of ()
?
I'd go for (vec (rest [1]))
, but that doesn't work if I'm doing (update some-map :key rest)
I'd go for (update some-map :key -> rest vec)
, but ->
isn't a function
Perf! Thanks Mike.
Yeah, that was my big desire, otherwise I'd have just done something dumb like (update some-map :key #(vec (rest %))
note that you could define that function as (comp vec rest)
:
=> ((comp vec rest) [1 2 3])
[2 3]
Totes! But that's still generating a new function instance every time that code is evaluated. This is some inner loop code, so I'm trying to keep things static.
Thanks for the tip.
actually, as far as i know, at runtime the JVM class for the function has already been generated; all it does at that point is new
that class up, which is handily pretty cheap. but point taken! 🙂
You can bind the function (comp vec rest) to a local name in a let and use it wherever, with no re-calculation of the function, of course.
Well, assuming the 'let' was outside the place that caused repeated use of the function. Either that or just defn yourself up a new function in the namespace and use that.
Yep, all valid options. Thanks guys.