This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-27
Channels
- # architecture (6)
- # beginners (36)
- # boot (4)
- # cider (74)
- # cljsrn (5)
- # clojure (87)
- # clojure-denver (2)
- # clojure-finland (2)
- # clojure-gamedev (5)
- # clojure-italy (10)
- # clojure-nl (1)
- # clojure-uk (45)
- # clojurescript (33)
- # code-reviews (5)
- # core-async (12)
- # cursive (17)
- # datascript (2)
- # datomic (71)
- # duct (4)
- # emacs (19)
- # figwheel (1)
- # fulcro (4)
- # garden (1)
- # hoplon (18)
- # jobs (5)
- # leiningen (2)
- # off-topic (73)
- # onyx (14)
- # overtone (2)
- # portkey (32)
- # re-frame (62)
- # reagent (46)
- # shadow-cljs (76)
- # spacemacs (2)
- # sql (14)
- # tools-deps (5)
- # yada (3)
Hi, I have a clojurescript app with clojure backend and now I am trying to send some static data (config) from the backend to the frontend on page load. I was thinking to send it as a JSON structure that the clojurescript app picks up. 1. Is there a better way? 2. If this is the best way, how do i convert a clojure map to a JSON map?
If you're the only client of that config (no third parties), then Transit (https://github.com/cognitect/transit-format) would be most efficient. But if you want to use JSON without Transit, then clj->js
then calling (js/JSON.stringify (clj->js {:a 5}))
would be the way https://cljs.github.io/api/cljs.core/clj-GTjs
excellent answer! Thanks @troglotit
but how can i convert to JSON on the backend_ clj->js
seem to only work in clojurescript?
https://github.com/dakrone/cheshire is a popular library for handling json in Clojure
There is also https://github.com/clojure/data.json as an alternative
@karl.jakob.lind Another approach if the data is truly static is to keep it in a .cljc
file that can be used both from Clojure and ClojureScript
Hi, when having two luminus
projects running with lein run
should one change the default port nr. 7000 for one of them? I'm asking this because tried to find the name of processes with lsof -i
but couldn't find any in that port.
Is there anyone tried to build an app with Reagent/Rum/etc with Apollo? Maybe there are blogposts or tutorials
I used re-graph, https://github.com/oliyh/re-graph to connect to a GraphQL endpoint. It's a nice small library that works well.
Hello I am trying to wrap my head around ring routing and the role of compojure in making the ring handlers. After some investigation, I found that the ring accepts the handler in which we have to explicitly match the route. The role of compojure is then to create a handler which on request calls (handler request) and if the route matches then it's called. Otherwise the nil is returned and other handlers for the route are called. I am very curious if I am right. If so then I would highly appreciate if you could explain to me why the ring is implemented in fashion when to match the route every single handler is taken into account. Wouldn't be better to have some sort of map which when the request occurs then matches to correct handler?
@kwcharllie379 Ring itself has no concept of routing. It defines a simple abstraction over HTTP request & response - requests are maps with certain keys, and responses are maps with certain keys. A ring handler is a function that takes a request and returns a response.
Compojure adds a layer of routing on top of this, as well as a number of syntactic and developer convenience features. When you use compojure’s routes
function or defroutes
macro, the result is a ring handler.
@michael.gaare Yes I understand it very well I think. But don't you think it's some kind of time consuming to go through all handlers in order to match the route?
@kwcharllie379 Well, that’s getting into the implementation details of how compojure handles routing. bidi is another routing library that uses a trie for this rather than compojure’s more linear approach
Yes this is what I tried to say it's linear approach.
Thank you @michael.gaare
Sorry, yes, linear on count routes defined
Which is likely a very small n
I do not think so. Simple route like "/users" has 4 handlers because of GET, POST, DELETE, PUT. So for evey route there are at least 1 to 4 handlers. Which in my opinion is not very optimal.
If that's a likely bottleneck, clojure won't perform well enough for the application
Also, linear search over a collection that small is faster than a hash lookup on real world cpus
Ooo really I didn't know that. Thank you very much for the clarification.
I really appreciate that.
Guide me please which path should I take? What do you prefer? I came from the Node.js world and I do not know which path should i take 1. Compojure and compojure-api 2. Pedestal
Pedestal also means not using ring, right?
Pedestal allows you to use ring, but it also has its own async middlewares thing that can be more performant if you target that
So pedestal is right choice, right?
Ring is some kind of express as I can see
Personally I’d go with compojure & compojure-api. Coming from node.js, it has this nice swagger UI built in
Ok maybe it's the right path, because I can find a lot of similarities between Node.js and Ring & Compojure and since I am beginner it would be better to explore the Clojure in the area in which I am comfortable. Thank you @michael.gaare @rauh @noisesmith
how do i use clojure.spec to validate the existence of a file? should i be doing that?
i'm reading in an edn file as a config file and i'd like to validate the config