This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-06
Channels
- # adventofcode (10)
- # ai (2)
- # aleph (2)
- # announcements (21)
- # beginners (25)
- # calva (7)
- # cider (19)
- # clj-kondo (28)
- # clj-on-windows (3)
- # cljdoc (6)
- # clojure (80)
- # clojure-dev (15)
- # clojure-europe (29)
- # clojure-italy (3)
- # clojure-nl (37)
- # clojure-uk (4)
- # clojurescript (3)
- # cloverage (1)
- # conjure (6)
- # core-async (2)
- # cursive (17)
- # datalevin (9)
- # datomic (7)
- # deps-new (23)
- # emacs (4)
- # figwheel-main (6)
- # fulcro (6)
- # honeysql (19)
- # improve-getting-started (4)
- # inf-clojure (2)
- # introduce-yourself (5)
- # jobs (1)
- # leiningen (6)
- # lsp (73)
- # malli (1)
- # nrepl (2)
- # off-topic (37)
- # polylith (9)
- # quil (2)
- # reitit (16)
- # releases (2)
- # remote-jobs (6)
- # rewrite-clj (38)
- # shadow-cljs (1)
- # tools-build (1)
@mhamzachippa When you get that data back from the API and you convert it from JSON to Clojure, you can do this to it
dev=> (update {:subscribed-events [1 2 3]} :subscribed-events set)
{:subscribed-events #{1 3 2}}
Alternatively, you could change your event code to
(re-frame/reg-event-fx
:add-subscribed-event
(fn-traced [{:keys [db]} [_ event_id]]
{:db (update-in db [:user :subscribed-events] (fn [events id] (conj (set events) id)) event_id)}))
; re-frame event to remove subscribed events from the database
(re-frame/reg-event-fx
:remove-subscribed-event
(fn-traced [{:keys [db]} [_ event_id]]
{:db (update-in db [:user :subscribed-events] (fn [events id] (disj (set events) id)) event_id)}))
That forces the subscribed events to be a set before trying to add/remove elements from it.(but fixing the data before you add it to the re-frame db map would be better!)
I’m trying to get started with tools.build
and cannot figure out what I’m doing wrong. I’m basically trying to follow the instructions here: https://clojure.org/guides/tools_build, but I can’t seem to get it to work. When I run my uberjar (built with clj -T:build uber
) using java -jar obeya-0.1.1-standalone.jar
, I get this error:
Error: Could not find or load main class obeya.main
Caused by: java.lang.ClassNotFoundException: obeya.main
This is my directory structure:
.
├── build.clj
├── deps.edn
├── src
│ └── obeya
│ └── main.clj
└── target
5 directories, 9 files
This is src/obeya/main.clj
:
(ns obeya.main)
(defn -main [opts]
(println "running"))
This is build.clj
:
(ns build
(:require [clojure.tools.build.api :as b]))
(def app 'obeya)
(def version (format "0.1.%s" (b/git-count-revs nil)))
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def uber-file (format "target/%s-%s-standalone.jar" (name app) version))
(defn clean [_]
(b/delete {:path "target"}))
(defn uber [_]
(clean nil)
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})
(b/compile-clj {:basis basis
:src-dirs ["src"]
:class-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file uber-file
:basis basis
:main 'obeya.main}))
This is my deps.edn
:
{:deps {}
:aliases
{:build {:deps {io.github.clojure/tools.build {:git/tag "v0.7.5" :git/sha "34727f7"}}
:ns-default build}}}
I’ve tried a bunch of things, but I have yet to get anything to work (either the build fails or I get the above error.)Do you have (:gen-class)
in the ns
form in obeya/main.clj
?
Without that, you won't get a Java-callable main class.
Indeed, that fixed my issue. I’m going to write something in #improve-getting-started about how I got stuck.
If you create an app project via clj-new or deps-new, (:gen-class)
should be present -- just like it is with lein new app myapp
or similar.
I didn’t know those things existed. I haven’t found mention of them in the documentation, otherwise I would have started with one of those.
Community projects are rarely mentioned in the official docs.
@seancorfield I changed it into maps now working like a charm. Thank you so much sir
Question about removing unneeded dependencies— I’m in the early stages of building an app/prototype and decided to use a different DB library. (No data committed yet; just changed my mind.) I already have the old one in deps.edn
. Do I need to do anything else besides remove that line and add the new one?
I assume because the app hasn’t been .jar
red yet, the old library won’t do any more harm than just taking up a few extra MB on my local hard drive. Is that correct?
I'm currently working through this (excellent) https://www.learn-clojurescript.com, and in https://www.learn-clojurescript.com/section-1/lesson-8-capstone-weather-forecasting-app/#calling-an-external-api, the author uses the following code to update an app-state
atom with new data returned from an API:
(swap! app-state update-in [:temperatures :today :value] (constantly today))
(swap! app-state update-in [:temperatures :tomorrow :value] (constantly tomorrow))
and I was wondering what the difference was between using update-in
with (constantly <value>)
and just using assoc-in
with <value>
.
I.e can I just do this instead:
(swap! app-state assoc-in [:temperatures :today :value] today)
This assoc-in
version seemed to work when I tested it, but is there some reason why using update-in
is preferred?Hi, there, I was using lein deps
in the past, to know the conflicting artificats I have in my dependency tree. Now, I'm using deps.edn, but I don't know how to do the same? and don't find any reference on the web
https://clojure.org/reference/deps_and_cli#_other_programs and https://clojure.org/reference/dep_expansion#_tree_printing
oh yes, It's a so tiny paragraph that I missed it. But as usual a simple and elegant solution, thx !