This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-24
Channels
- # arachne (3)
- # beginners (39)
- # boot (3)
- # cider (91)
- # cljs-dev (56)
- # cljsrn (4)
- # clojure (267)
- # clojure-dusseldorf (1)
- # clojure-estonia (1)
- # clojure-greece (2)
- # clojure-italy (6)
- # clojure-nl (2)
- # clojure-russia (18)
- # clojure-spec (27)
- # clojure-uk (136)
- # clojurescript (19)
- # core-async (2)
- # cursive (6)
- # datomic (17)
- # emacs (2)
- # fulcro (86)
- # graphql (4)
- # hoplon (13)
- # jobs-discuss (7)
- # jobs-rus (1)
- # keechma (34)
- # keyboards (7)
- # leiningen (5)
- # luminus (4)
- # lumo (8)
- # off-topic (13)
- # om (6)
- # onyx (26)
- # re-frame (22)
- # reagent (1)
- # reitit (2)
- # remote-jobs (8)
- # ring (3)
- # ring-swagger (5)
- # rum (8)
- # shadow-cljs (45)
- # specter (6)
- # unrepl (16)
- # yada (15)
hey there!
I love Amsterdam, but the last time I was there Amsterdam inside Singel was just made of hassle and stag/hen parties
My wife went there for a conference and said it was lovely once she got outside the 'tourist' zones
Morning :wind_blowing_face:
I liked Amsterdam when I tried it out, but itās been over 10 yearsā¦ My wife has visited the city many times and has a particular love for the place.
I reckon that it gets more than its share of stag / hen action, but just staying out of the Red Light negates 80% of that action, I reckonā¦
(I have a friend whoās been living there for a long time who I recently re-acquainted myself with as he was in Manila on business a couple of times while we were out there and heās very positive about the ālocalā scene, i.e. whatās there thatās not for the touristsā¦)
I think Amsterdam is trying to get less stag/hen parties these days and the red-light district is a lot smaller these days as well.
@thomas - Yeah, I think thatās been a conscious move by the City, from what I hear. Itās always going to have that underbelly and there are always going to be people that visit it for that, but it has so much more to it as a place, and I was only there for 3 nights! (I was with a friend for her birthday and coffee shops were not an option as she was vehemently anti-drug!)
Not sure if this is still maintained but iāve seen this before https://github.com/danlentz/clj-uuid
(I have just realised that I need to create them on both sides, client and server, and would prefer to be able to create v5 ones - will fall back to something else if necessary)
and I could__ do an XHR call for any UUIDs I need from the server, but having a client-side equivalent library would be fab
If there isnāt one I will make an endpoint in my API to fetch one when needed and use that š
@maleghast we use v1 and v5 UUIDs, but i never found a js lib which could produce them, so we generate all v1 and v5 UUIDs server-side
Thanks @mccraigmccraig - I am assuming that I need to do the same and I am debugging my utility endpoint that returns a UUID nowā¦
I do have another Q thoughā¦ Why does my function return exactly the same result for every v5 UUID..?
uh - what is your function doing ?
v5 UUIDs are deterministic
same inputs, same output
it's a way of taking a random (v1, v4) UUID and namespacing it
v1 UUIDs are time-based - if you use cassandra, and maybe other dbs, they will sort timewise... they aren't very random though - it's got your MAC address and timestamp and a counter in
v4 UUIDs are almost all random bits
so depends on what you want to use the uuid for
e.g. we use v4 UUIDs for auth tokens and v1 UUIDs for message identifiers
but you can generate v4 uuids in js...
as long as you don't care about sort order or namespacing, that will be fine for unique ids
Well, I am going to want v5s for auth tokens later on, so learning how to do this is going to be useful anyway, but that might be a better approach for this particular use-case.
why do you want v5s for auth tokens ?
I thought v5 allows UUIDs to be namespaced, so you can have UUIDs that are valid only in a particular context..?
Itās entirely possible that I have misunderstood them more than even I had considered
ā¦ Yeah, I have misunderstood them completely it would appearā¦ (I did some re-reading)
v4 UUIDs would be fine for what I want, in fact v1 UUIDs would almost certainly be fine for the specific thing I am doing right_now__
I donāt need randomness, there is no security aspect to the UUIDs I need for what I am dealing with right now, all I NEED is uniqueness and the time dimension of v1 UUIDs will give me that, job done.
I have an endpoint that is returning the same result over and over, but when I run the underlying function (that creates the response for the Yada Resource) in my REPL I get what I expect, a different result time after time.
yada does not cache responses @maleghast
make sure that you are not executing the code to define the response when you declare the response - if you give yada a static value as a response (rather than a fn) it will repeatedly return that
@mccraigmccraig - Thatās it!
@shan - I tried it, it does not work, in fact I get this error:
{:response
{:headers {},
:vary #{},
:produces
{:media-type
{:name "application/edn",
:type "application",
:subtype "edn",
:parameters {},
:quality 1.0},
:charset {:alias "UTF-8", :quality 1.0}}},
:resource yada.resource.Resource,
:error #error {
:cause "Wrong number of args (1) passed to: admin/create-uuid"
:via
[{:type clojure.lang.ArityException
:message "Wrong number of args (1) passed to: admin/create-uuid"
:at [clojure.lang.AFn throwArity "AFn.java" 429]}]
:trace
[[clojure.lang.AFn throwArity "AFn.java" 429]
[clojure.lang.AFn invoke "AFn.java" 32]
[yada.methods$eval24714$fn__24715 invoke "methods.clj" 153]
[yada.methods$eval24683$fn__24684$G__24674__24691 invoke "methods.clj" 138]
[yada.methods$eval24723$fn__24730$fn__24739 invoke "methods.clj" 192]
[manifold.deferred$eval18026$chain___18047 invoke "deferred.clj" 863]
[clojure.lang.AFn applyToHelper "AFn.java" 165]
[clojure.lang.RestFn applyTo "RestFn.java" 132]
[clojure.core$apply invokeStatic "core.clj" 661]
[clojure.core$apply invoke "core.clj" 652]
[manifold.deferred$eval18026$chain___18047$fn__18051 invoke "deferred.clj" 889]
[manifold.deferred.Listener onSuccess "deferred.clj" 219]
[manifold.deferred.Deferred$fn__17825 invoke "deferred.clj" 378]
[clojure.lang.AFn run "AFn.java" 22]
[io.aleph.dirigiste.Executor$Worker$1 run "Executor.java" 62]
[manifold.executor$thread_factory$reify__17228$f__17229 invoke "executor.clj" 44]
[clojure.lang.AFn run "AFn.java" 22]
[java.lang.Thread run "Thread.java" 745]]}}
I admit that I am not completely clear as to why this happens, but having the parens makes it work, so I will leave them in for now and worry about the āwhy?ā in a little whileā¦
probably yada is passing the request context to the create-uuid fn @maleghast
a typical :response
fn looks like
(fn [ctx]
(case (:method ctx)
:options (yada.context/->Response)
:get (generate-string api-version)))
I have this:
(yada/resource
{:id :foundation.resources/fetch-uuid
:description "API call for getting v5 UUIDs generated on the server and returned to the front end."
:parameters {}
:produces [{:media-type #{"application/edn"}
:charset "UTF-8"}]
:methods
{:get
{:response
(fn [] (create-uuid))}}})
so the type of request is filtered before the response is handled / createdthat sounds very reasonable @maleghast
If I have a function that is talking to the server from ClojureScript, how do I block on the response..?
@maleghast you don't block - it's javascript!
Ok, so I want to fetch a UUID from the server and bind it to a local symbol inside a let binding at the top of a function containing a component.
At the moment the function works (if I println the function I get a UUID from the server), but the local val in the let is nil
I assume that this means the function has not returned from the server fast enough to resolve the value
Hereās my fetch:
(defn fetch-uuid
"Function to retrieve a new UUID"
[]
(let [response (atom nil)]
(doto
(new js/XMLHttpRequest)
(.open "GET" "/admin/util/uuid")
(.setRequestHeader "Accept" "application/edn")
(.addEventListener
"load"
(fn [evt]
(reset! response (read-string evt.currentTarget.responseText))))
(.send))
(when @response
@response)))
it's async land @maleghast - rather than wait, you schedule something to happen when the value arrives. i tend to prefer promises (promesa is a good lib) and many people use core.async
(I know I can do the UUIDs client-side based on earlier conversation, but I want to understand how to do this anyway)
Ah ok, so if the above were wrapped in a promise, I could pass the promise back to my component function and whenever the data was present the value would be resolved..?
not really - you can schedule a then
operation to be called when the value resolves (promises), or use a go
block to do something when your response channel gets an item
if you are using reagent you would use the then
or go
to update your state somewhere... with re-frame you would dispatch an event to update your state
So, if I make the request and then updated the app-state the component would only render when the change to app-state happens?
are you using re-frame or reagent ?
have a gander at this @maleghast - it may give you some food for thought - https://github.com/Day8/re-frame/blob/master/docs/FAQs/DoINeedReFrame.md
@mccraigmccraig - I am going to read that in a bit; for now your advice has got me moving again so I want to see how much more progress I can make before I stop for dinner, but I will__ read that article and I am definitely open to adopting re-frame.
in summary - if you aren't expecting your app to ever be anything more than simple, stick with reagent. if it's going to grow and grow, do your future self a favour and choose something else. i've been happy with re-frame, but there seem to be a couple of other reagent based thingies now too
Sounds like good advice to me. If youāre having good experiences / results from re-frame I donāt imagine I will look any further. I will wait for a lot of people to be āpushingā something else before I think about anything different š
For our small/medium front-end, I've found it more of a burden to work with event passing. Swapping into an atom was simpler, although tests were somewhat easier with events.
Can anyone point me at a user-friendly / easy guide to handling forms in Reagent..?
I want to swap the data into the app-state and send the data to the back-end for persistence, by stepping in and preventDefault-ing the submit event.
All I can find by Google-Fu failure is stuff from 2-3 years ago, and I am hoping__ that itās gotten simplerā¦
In onSubmit use this: https://github.com/ccfontes/form-juice &preventDefault
I do it slightly differently, as I run the function in the onSubmit for the form, but it's the same effect.
Basically it reads the form as data (DOM state), rather than re-rendering for every attempt at input. It has limitations, but it's very easy.
So, if I just hand the āeā of the event to a function that then grabs the form data by using the āsqueezeā function in the namespace provided..?