Playing around with a "system" concept, where a simple view of all the states can be created by (mount/system)
, and used.
This could probably be used for testing, although a simple :require
does not seem all that frightening in tests.
(ns raffle | |
(:require [raffle.system :refer [find-by-id]] | |
[clojure.tools.logging :refer [info]])) | |
(defn raffle-it [] | |
(let [id (rand-int 42)] | |
(info "and the winner is... " | |
(find-by-id id)))) |
;; Bootstrapped ClojureScript | |
;; -------------------------- | |
cljs.user=> (require '[cljs.js :as cljs]) | |
cljs.user=> (def foo 42) | |
#'cljs.user/foo | |
cljs.user=> (cljs/eval-str (cljs/empty-state) "(ns-interns (quote cljs.user))" "interning" {:eval cljs/js-eval} identity) | |
{:ns cljs.user, :value {}} |
;; useful for test / dev tasks | |
(defn dep-to-attrs [dep] | |
(into {} (map vec (partition 2 dep)))) | |
(defn attrs-to-dep [attrs] | |
(->> attrs | |
(apply vector) | |
(apply concat) | |
vec)) |
dev=> (mount/stop) | |
{:stopped ["#'app.example/nrepl" "#'app.www/nyse-app" "#'app.db/conn"]} | |
;; swapping nRPEL with 42 | |
dev=> (mount/start-with {#'app.example/nrepl 42}) | |
{:started ["#'app.conf/config" "#'app.db/conn" "#'app.www/nyse-app" "#'app.example/nrepl"]} | |
dev=> @#'app.example/nrepl | |
42 |
(defn connect [db-spec] | |
(jdbc/get-connection db-spec)) | |
(defn disconnect [conn] | |
(.close conn)) |
(deftask build [] | |
(comp | |
(pom) ;; <<< names the file correctly + no need for --file in "(ubermain)" or "(push)" | |
(ubermain) | |
(sift :include #{#"stream-on.*.jar$"}) | |
(target))) | |
(deftask deploy-snapshot [] | |
(comp | |
(build) |
for Boot, slides and help with Boot intel.
for slides and help with Lein pitfals
(defn deref-state [name] | |
(let [{:keys [status inst] :as state} (@meta-state name)] | |
(when-not (:started status) | |
(up name state (atom #{}))) | |
@inst)) | |
(defn throw-not-started [name] | |
(throw-runtime (str "can't use \"" name "\" state, since it was not started. " | |
"this would usually happen if you forget to start it explicitly " | |
"or to \":require\" this state or its namespace, " |
;; [tolitius:/tmp/ido]$ cat src/ido/core.clj | |
(ns ido.core | |
(:require [mount.core :refer [defstate]])) | |
(defstate kafka :start 42 | |
:stop 0) | |
;; [tolitius:/tmp/ido]$ | |
;; [tolitius:/tmp/ido]$ lein install | |
;; Created /private/tmp/ido/target/ido-0.1.0-SNAPSHOT.jar |