Fork me on GitHub
#beginners
<
2017-10-06
>
Lucas Barbosa02:10:26

Is it safe to share Java objects between threads in clojure?

Lucas Barbosa02:10:38

a client Socket, for instance

Lucas Barbosa02:10:55

like (future (handle-client socket))

Lucas Barbosa02:10:51

I’m not doing concurrent access, but I am worried about stale data, for instance

noisesmith02:10:37

if nothing else uses the socket, it's safe

raheel04:10:14

I have a working app with a clojure + clojurescript application. The backend serves the initial HTML, with the base components. The frontend makes AJAX calls to the backend, which has couple of API endpoints, and then the components get reloaded with the response data. The AJAX calls works fine this way with a production cljs build, where the HTML is being served by the same port as the API endpoints. My newbie question: how can I make the AJAX calls work when the HTML is being served by figwheel. (The port is being used figwheel, so I can't use it to serve the backend)

seancorfield05:10:49

@raheel Not sure if the #figwheel or #lein-figwheel channels might be more able to help? It's a bit late for most folks to be around (10pm Pacific; 1am Eastern) -- maybe ask again earlier tomorrow?

raheel05:10:09

thanks @seancorfield. I am probably very fuzzy about the concepts here, but managed to solve this for now: run the server and figwheel on separate port. Navigate to the figwheel port in the browser and let it connect. Then navigate to the server port in the browser, and reloading works in that page as well.

lovuikeng06:10:19

that's how dev workflow should work, @raheel with figwheel running dev mode on default 3449, and server backend running on default 3000, great that you've already figured that out 🙂

qle-guen07:10:29

anyone knows some kind of binding that executes #(-> % f g h)

qle-guen07:10:41

something like fn-> ?

qle-guen07:10:32

nvm, that's just comp :thinking_face:

sundarj08:10:42

@qle-guen it is comp, except that function composition is right-to-left, so for the example you gave it would be (comp h g f)

qle-guen08:10:03

yes but from what I understand of it, partial application is different from threading

qle-guen08:10:33

because threading just inserts the argument at the end of the list

qle-guen08:10:48

or at the second place with ->

sundarj08:10:50

indeed you are - however in your example you wrapped the threading macro in an anonymous function; and when everything you're threading the data through are functions, then that is equivalent to function composition

sundarj08:10:52

comp isn't partial application fyi, you just pass the results from each function call to the next - like you did with the threading macro

sundarj08:10:56

partial application would be (def add-six (partial + 6))

qle-guen08:10:18

yes, it's because I come from Haskell where everything is curried

sundarj08:10:56

ah right, fair enough!

qle-guen08:10:59

so I'm not really used to think about these distinctions

sundarj08:10:15

understandable

madstap11:10:22

@qle-guen FWIW, my util lib has that exact macro. (defmacro fn-> [& forms] (fn [x#] (-> x# ~@forms))) (the body is syntax quoted, which I don't know how to escape in slack...)

stvnmllr215:10:51

Not specific to clojure necessarily, anyone seen a good example of not using sessions for authentication for a rest api on a SPA? Tried the following: 1) Using fb login client side, which then passes token to server, which validates token and creates jwt token for app. This works, but all of a sudden stopped on my android phone browser. 2) Used browser redirects to fb login, but once i authenticate, not sure how to redirect back to my app without a session. Seems i should use an https cookie to store the token, but coludn't find how the buddy auth lib validates against a cookie (I could write it myself i guess) So yeah, been reading, and watching an looking at examples. But none seem to be complete front-end and backend auth. though i'd ask here to makes sure i didn't miss anything obvious.

stvnmllr216:10:36

Thanks @lovuikeng I am using buddy. Looking for something that shows client/server side auth with an external auth service. fb, auth0. Maybe there is part of it that i missed though, will keep reading.

stvnmllr216:10:21

@lovuikeng That does show how to use the cookie to store the jwt, so might get me closer to writing one. thanks.