From e247636be697d6c1dc6cebd703ea4ee6b8d9b7d4 Mon Sep 17 00:00:00 2001 From: anatoly Date: Thu, 15 Mar 2018 23:50:42 -0400 Subject: [PATCH] reformat all with linter --- dev/clj/app/conf.clj | 6 +++--- dev/clj/app/db.clj | 4 ++-- dev/clj/app/nyse.clj | 2 +- dev/clj/app/utils/logging.clj | 6 +++--- dev/clj/app/www.clj | 8 ++++---- dev/cljs/app/audit_log.cljs | 4 ++-- dev/cljs/app/example.cljs | 2 +- dev/resources/config.edn | 2 +- doc/clojurescript.md | 14 +++++++------- project.clj | 2 +- src/mount/core.cljc | 10 +++++----- test/clj/tapp/conf.clj | 6 +++--- test/clj/tapp/example.clj | 6 +++--- test/clj/tapp/utils/logging.clj | 6 +++--- test/cljs/tapp/audit_log.cljs | 4 ++-- test/cljs/tapp/example.cljs | 2 +- test/core/mount/test/cleanup_deleted_states.cljc | 6 +++--- test/core/mount/test/cleanup_dirty_states.cljc | 2 +- test/core/mount/test/composable_fns.cljc | 8 ++++---- test/core/mount/test/fun_with_values.cljc | 2 +- test/core/mount/test/helper.cljc | 4 ++-- test/core/mount/test/on_reload.cljc | 8 ++++---- test/core/mount/test/parts.cljc | 6 +++--- test/core/mount/test/private_fun.cljc | 6 +++--- test/core/mount/test/start_with.cljc | 4 ++-- test/core/mount/test/start_with_states.cljc | 4 ++-- test/core/mount/test/start_without.cljc | 2 +- test/core/mount/test/stop_except.cljc | 4 ++-- 28 files changed, 70 insertions(+), 70 deletions(-) diff --git a/dev/clj/app/conf.clj b/dev/clj/app/conf.clj index 3273a95..3e7ee6f 100644 --- a/dev/clj/app/conf.clj +++ b/dev/clj/app/conf.clj @@ -5,9 +5,9 @@ (defn load-config [path] (info "loading config from" path) - (-> path - slurp + (-> path + slurp edn/read-string)) -(defstate config +(defstate config :start (load-config "dev/resources/config.edn")) diff --git a/dev/clj/app/db.clj b/dev/clj/app/db.clj index aed7bb7..4670f79 100644 --- a/dev/clj/app/db.clj +++ b/dev/clj/app/db.clj @@ -1,4 +1,4 @@ -(ns app.db +(ns app.db (:require [mount.core :refer [defstate]] [datomic.api :as d] [clojure.tools.logging :refer [info]] @@ -34,7 +34,7 @@ :db/valueType :db.type/bigdec :db/cardinality :db.cardinality/one :db.install/_attribute :db.part/db} - + {:db/id #db/id [:db.part/db] :db/ident :order/qty :db/valueType :db.type/long diff --git a/dev/clj/app/nyse.clj b/dev/clj/app/nyse.clj index 1d45255..a56f2c4 100644 --- a/dev/clj/app/nyse.clj +++ b/dev/clj/app/nyse.clj @@ -11,6 +11,6 @@ (defn find-orders [conn ticker] (let [orders (d/q '[:find ?e :in $ ?ticker - :where [?e :order/symbol ?ticker]] + :where [?e :order/symbol ?ticker]] (d/db conn) ticker)] (touch conn orders))) diff --git a/dev/clj/app/utils/logging.clj b/dev/clj/app/utils/logging.clj index e2a7bab..056d078 100644 --- a/dev/clj/app/utils/logging.clj +++ b/dev/clj/app/utils/logging.clj @@ -1,4 +1,4 @@ -(ns app.utils.logging ;; << change to your namespace/path +(ns app.utils.logging ;; << change to your namespace/path (:require [mount.core] [robert.hooke :refer [add-hook clear-hooks]] [clojure.string :refer [split]] @@ -21,9 +21,9 @@ :down "<< stopping" false)) -(defn log-status [f & args] +(defn log-status [f & args] (let [[state-name state] args - action (f-to-action f state)] + action (f-to-action f state)] (when-let [taking-over-the-world (whatcha-doing? action)] (info (str taking-over-the-world ".. " state-name))) (apply f args))) diff --git a/dev/clj/app/www.clj b/dev/clj/app/www.clj index 8c02986..c419f9f 100644 --- a/dev/clj/app/www.clj +++ b/dev/clj/app/www.clj @@ -14,10 +14,10 @@ (GET "/nyse/orders/:ticker" [ticker] (generate-string (find-orders conn ticker))) - (POST "/nyse/orders" [ticker qty bid offer] - (let [order {:ticker ticker - :bid (bigdec bid) - :offer (bigdec offer) + (POST "/nyse/orders" [ticker qty bid offer] + (let [order {:ticker ticker + :bid (bigdec bid) + :offer (bigdec offer) :qty (Integer/parseInt qty)}] (add-order conn order) (generate-string {:added order})))) diff --git a/dev/cljs/app/audit_log.cljs b/dev/cljs/app/audit_log.cljs index 9ce586c..d12eddf 100644 --- a/dev/cljs/app/audit_log.cljs +++ b/dev/cljs/app/audit_log.cljs @@ -13,13 +13,13 @@ (defn find-source-logs [db source] (d/q '{:find [?t ?msg] - :in [$ ?s] + :in [$ ?s] :where [[?e :source ?s] [?e :timestamp ?t] [?e :msg ?msg]]} @@db source)) (defn find-all-logs [db] - (->> (map :e (d/datoms @@db :aevt :timestamp)) + (->> (map :e (d/datoms @@db :aevt :timestamp)) dedupe (d/pull-many @@db '[:timestamp :source :msg]))) diff --git a/dev/cljs/app/example.cljs b/dev/cljs/app/example.cljs index 2b9b475..4e36231 100644 --- a/dev/cljs/app/example.cljs +++ b/dev/cljs/app/example.cljs @@ -12,7 +12,7 @@ " → [" (name source) "]: " msg)) (defn show-log [] - (.write js/document + (.write js/document (html [:ul (doall (for [e (find-all-logs log)] [:li (format-log-event e)]))]))) diff --git a/dev/resources/config.edn b/dev/resources/config.edn index dd8d3fd..82a8bea 100644 --- a/dev/resources/config.edn +++ b/dev/resources/config.edn @@ -1,4 +1,4 @@ -{:datomic +{:datomic {:uri "datomic:mem://mount"} :www {:port 4242} diff --git a/doc/clojurescript.md b/doc/clojurescript.md index 9fad5bf..7cd5566 100644 --- a/doc/clojurescript.md +++ b/doc/clojurescript.md @@ -8,7 +8,7 @@ - [Using States](#using-states) - [Thanks](#thanks) -In case you need to manage state in ClojureScript using mount, _all_ the mount Clojure features are supported in ClojureScript. +In case you need to manage state in ClojureScript using mount, _all_ the mount Clojure features are supported in ClojureScript. Which means all the mount Clojure [documentation](../README.md) is the mount ClojureScript documentation. With a slight change in [_mode_](clojurescript.md#mount-modes) ( no change in _mood_ though, just the _mode_ :)). @@ -16,19 +16,19 @@ With a slight change in [_mode_](clojurescript.md#mount-modes) ( no change in _m ### The "Why" Since [reader conditionals](http://clojure.org/reader#The%20Reader--Reader%20Conditionals) were added in Clojure 1.7, -it became a lot easier to target both platforms with lots of code reuse. You might have noticed +it became a lot easier to target both platforms with lots of code reuse. You might have noticed that most of mount code lives in `.cljc` files. -The way mount is designed it "mounts" itself to a solid Clojure [namespace API](http://clojure.org/namespaces), +The way mount is designed it "mounts" itself to a solid Clojure [namespace API](http://clojure.org/namespaces), and while `.cljc` helps a lot with targeting Clojure and ClojureScript, JavaScript VM is vastly different from JVM. -Since JavaScript mostly tagrets browsers, mobile devices and IoT, +Since JavaScript mostly tagrets browsers, mobile devices and IoT, it is quite important to [compress](https://github.com/clojure/clojurescript/wiki/Advanced-Compilation) the final result. Which means that Clojure namespaces API are not that well supported in ClojureScript, since they get renamed and optimized -during compilation + of course no native namespace support on the JavaScript side +during compilation + of course no native namespace support on the JavaScript side (but that is somewhat solved with [Google Closure](https://closure-library.googlecode.com/git-history/docs/local_closure_goog_base.js.source.html#line428)). -But. When developing an application in Clojure and ClojureScript, it would only make sense if the API for any library +But. When developing an application in Clojure and ClojureScript, it would only make sense if the API for any library would be _identical_ for both platforms. It should be transparent for developers whether they use a library in Clojure or ClojureScript. It is not possible for all libraries (i.e. concurrency, reified Vars, etc.), but we should try to make it possible for most. @@ -52,7 +52,7 @@ To switch Mount into this mode do: anywhere before a call to `(mount/start)`, usually at the entry point of an app: in the `-main`, web handler, etc. -This sets mount into the `cljc` mode. In this mode mount supports _both_: Clojure and ClojureScript with one difference +This sets mount into the `cljc` mode. In this mode mount supports _both_: Clojure and ClojureScript with one difference from the default `clj` mode: > all states are "_derefable_" diff --git a/project.clj b/project.clj index e613f7c..02f9081 100644 --- a/project.clj +++ b/project.clj @@ -7,7 +7,7 @@ :source-paths ["src"] :dependencies [] ;; for visual clarity - + :profiles {:dev {:source-paths ["dev" "dev/clj" "test/clj"] :dependencies [[org.clojure/clojure "1.7.0"] [org.clojure/clojurescript "1.7.170"]; :classifier "aot"] diff --git a/src/mount/core.cljc b/src/mount/core.cljc index 466fcf8..913e636 100644 --- a/src/mount/core.cljc +++ b/src/mount/core.cljc @@ -146,7 +146,7 @@ (and (status :started) (= :noop on-reload))))) -;;TODO: make private after figuring out the inconsistency betwen cljs compile stages +;;TODO: make private after figuring out the inconsistency betwen cljs compile stages ;; (i.e. _sometimes_ this, if private, is not seen by expanded "defmacro" on cljs side) (defn mount-it [s-var s-name s-meta] (let [with-inst (assoc s-meta :inst (atom (NotStartedState. s-name)) @@ -160,8 +160,8 @@ (up s-name with-inst (atom #{}))))) #?(:clj - (defmacro defstate - "Defines a state. Restarts on recompilation. + (defmacro defstate + "Defines a state. Restarts on recompilation. Pass ^{:on-reload :noop} to prevent auto-restart on ns recompilation, or :stop to stop on recompilation." [state & body] @@ -309,14 +309,14 @@ (intersection (mapset var-to-str these) (mapset var-to-str states)))) -(defn with-args +(defn with-args ([args] (with-args (find-all-states) args)) ([states args] (reset! -args args) ;; TODO localize states)) -(defn except +(defn except ([states] (except (find-all-states) states)) ([states these] diff --git a/test/clj/tapp/conf.clj b/test/clj/tapp/conf.clj index 6c821ba..4c58364 100644 --- a/test/clj/tapp/conf.clj +++ b/test/clj/tapp/conf.clj @@ -7,9 +7,9 @@ (defn load-config [path] (info "loading config from" path) - (-> path - slurp + (-> path + slurp edn/read-string)) -(defstate config +(defstate config :start (load-config "dev/resources/config.edn")) diff --git a/test/clj/tapp/example.clj b/test/clj/tapp/example.clj index 721d2da..93e4bcf 100644 --- a/test/clj/tapp/example.clj +++ b/test/clj/tapp/example.clj @@ -30,7 +30,7 @@ :db/valueType :db.type/bigdec :db/cardinality :db.cardinality/one :db.install/_attribute :db.part/db} - + {:db/id #db/id [:db.part/db] :db/ident :order/qty :db/valueType :db.type/long @@ -51,11 +51,11 @@ :order/bid bid :order/offer offer :order/qty qty}])) - + (defn find-orders [ticker] ;; can take connection as param (let [orders (d/q '[:find ?e :in $ ?ticker - :where [?e :order/symbol ?ticker]] + :where [?e :order/symbol ?ticker]] (d/db @nyse/conn) ticker)] (touch @nyse/conn orders))) diff --git a/test/clj/tapp/utils/logging.clj b/test/clj/tapp/utils/logging.clj index 6764aed..1db1b67 100644 --- a/test/clj/tapp/utils/logging.clj +++ b/test/clj/tapp/utils/logging.clj @@ -1,4 +1,4 @@ -(ns tapp.utils.logging ;; << change to your namespace/path +(ns tapp.utils.logging ;; << change to your namespace/path (:require [mount.core] [robert.hooke :refer [add-hook clear-hooks]] [clojure.string :refer [split]] @@ -21,9 +21,9 @@ :down "<< stopping" false)) -(defn log-status [f & args] +(defn log-status [f & args] (let [[state-name state] args - action (f-to-action f state)] + action (f-to-action f state)] (when-let [taking-over-the-world (whatcha-doing? action)] (info (str taking-over-the-world ".. " state-name))) (apply f args))) diff --git a/test/cljs/tapp/audit_log.cljs b/test/cljs/tapp/audit_log.cljs index 0eac430..088a603 100644 --- a/test/cljs/tapp/audit_log.cljs +++ b/test/cljs/tapp/audit_log.cljs @@ -13,13 +13,13 @@ (defn find-source-logs [db source] (d/q '{:find [?t ?msg] - :in [$ ?s] + :in [$ ?s] :where [[?e :source ?s] [?e :timestamp ?t] [?e :msg ?msg]]} @@db source)) (defn find-all-logs [db] - (->> (map :e (d/datoms @@db :aevt :timestamp)) + (->> (map :e (d/datoms @@db :aevt :timestamp)) dedupe (d/pull-many @@db '[:timestamp :source :msg]))) diff --git a/test/cljs/tapp/example.cljs b/test/cljs/tapp/example.cljs index 5f8808a..26b9351 100644 --- a/test/cljs/tapp/example.cljs +++ b/test/cljs/tapp/example.cljs @@ -12,7 +12,7 @@ " → [" (name source) "]: " msg)) (defn show-log [] - (.write js/document + (.write js/document (html [:ul (doall (for [e (find-all-logs log)] [:li (format-log-event e)]))]))) diff --git a/test/core/mount/test/cleanup_deleted_states.cljc b/test/core/mount/test/cleanup_deleted_states.cljc index 79d7a38..6e65325 100644 --- a/test/core/mount/test/cleanup_deleted_states.cljc +++ b/test/core/mount/test/cleanup_deleted_states.cljc @@ -11,7 +11,7 @@ [mount.test.helper :refer [dval helper forty-two]])) (def status (atom :a-not-started)) -(defstate a :start (reset! status :a-started) +(defstate a :start (reset! status :a-started) :stop (reset! status :a-stopped)) #?(:clj (alter-meta! *ns* assoc ::load false)) @@ -30,11 +30,11 @@ (testing "should cleanup/stop a state after it was deleted from ns" (is (empty? (:started (mount/start)))) ;; on any mount op (not necessarily on "stop") (is (= :a-stopped @status)) - (is (not (some #{"#'mount.test.cleanup-deleted-states/a"} + (is (not (some #{"#'mount.test.cleanup-deleted-states/a"} (keys @@#'mount.core/meta-state))))) (testing "should not stop it again on stop (should not be there by this point)") - (is (not (some #{"#'mount.test.cleanup-deleted-states/a"} + (is (not (some #{"#'mount.test.cleanup-deleted-states/a"} (-> (mount/stop) :stopped set)))))) ;; (t/run-tests) diff --git a/test/core/mount/test/cleanup_dirty_states.cljc b/test/core/mount/test/cleanup_dirty_states.cljc index 56bc741..816a326 100644 --- a/test/core/mount/test/cleanup_dirty_states.cljc +++ b/test/core/mount/test/cleanup_dirty_states.cljc @@ -48,7 +48,7 @@ (.require js/goog "mount.test.helper") ;; should have run :stop of `helper` ;; (is (= :cleaned @forty-two)) ;; TODO: figure out how to reload a namespace properly ;; (is (instance? mount.core.NotStartedState (dval helper))) - (mount/start #'mount.test.helper/helper) + (mount/start #'mount.test.helper/helper) (is (= :started (dval helper))) (mount/stop) (is (instance? mount.core.NotStartedState (dval helper)))))) diff --git a/test/core/mount/test/composable_fns.cljc b/test/core/mount/test/composable_fns.cljc index b8b6ee2..c43e4eb 100644 --- a/test/core/mount/test/composable_fns.cljc +++ b/test/core/mount/test/composable_fns.cljc @@ -31,14 +31,14 @@ #?(:clj (deftest only-states - (testing "only should only return given states. + (testing "only should only return given states. if source set of states is not provided, it should use all the states to select from" - (is (= #{"#'mount.test.composable-fns/test-conn" "#'tapp.example/nrepl" "#'tapp.nyse/conn"} + (is (= #{"#'mount.test.composable-fns/test-conn" "#'tapp.example/nrepl" "#'tapp.nyse/conn"} (only #{"#'is.not/here" #'mount.test.composable-fns/test-conn #'tapp.example/nrepl #'tapp.nyse/conn})))) (testing "only should only return given states" - (is (= #{"#'mount.test.composable-fns/test-conn" "#'tapp.example/nrepl"} - (only [#'mount.test.composable-fns/test-conn #'tapp.example/nrepl #'tapp.nyse/conn] + (is (= #{"#'mount.test.composable-fns/test-conn" "#'tapp.example/nrepl"} + (only [#'mount.test.composable-fns/test-conn #'tapp.example/nrepl #'tapp.nyse/conn] #{"#'is.not/here" #'mount.test.composable-fns/test-conn #'tapp.example/nrepl})))))) #?(:clj diff --git a/test/core/mount/test/fun_with_values.cljc b/test/core/mount/test/fun_with_values.cljc index 667f216..f8a5042 100644 --- a/test/core/mount/test/fun_with_values.cljc +++ b/test/core/mount/test/fun_with_values.cljc @@ -43,7 +43,7 @@ #'mount.test.fun-with-values/private-f #'mount.test.fun-with-values/f-value)) -(use-fixtures :once +(use-fixtures :once #?(:cljs {:before start-states :after mount/stop} :clj #((start-states) (%) (mount/stop)))) diff --git a/test/core/mount/test/helper.cljc b/test/core/mount/test/helper.cljc index e020c5c..642e951 100644 --- a/test/core/mount/test/helper.cljc +++ b/test/core/mount/test/helper.cljc @@ -5,10 +5,10 @@ #?(:clj (alter-meta! *ns* assoc ::load false)) -(defn dval +(defn dval "returns a value of DerefableState without deref'ing it" [d] - (-> (@@(var mount.core/meta-state) + (-> (@@(var mount.core/meta-state) #?(:clj (.name d) :cljs (.-name d))) :inst diff --git a/test/core/mount/test/on_reload.cljc b/test/core/mount/test/on_reload.cljc index 72e8ca0..7364176 100644 --- a/test/core/mount/test/on_reload.cljc +++ b/test/core/mount/test/on_reload.cljc @@ -7,7 +7,7 @@ [tapp.audit-log :refer [log]]] :clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]] [mount.core :as mount :refer [defstate]] - [tapp.example]]) + [tapp.example]]) [mount.test.helper :refer [dval helper forty-two counter inc-counter]] [mount.test.on-reload-helper :refer [a b c]])) @@ -42,14 +42,14 @@ ;; "b" is marked as :stop on reload (is (instance? mount.core.NotStartedState (dval b))) - (is (= (-> pre-reload :b :started) + (is (= (-> pre-reload :b :started) (-> @counter :b :started))) - (is (= (inc (-> pre-reload :b :stopped)) + (is (= (inc (-> pre-reload :b :stopped)) (-> @counter :b :stopped))) ;; "c" is not marked on reload, using "restart" as default (is (= :started (dval c))) (is (= (inc (-> pre-reload :c :started)) (-> @counter :c :started))) - (is (= (inc (-> pre-reload :c :stopped)) + (is (= (inc (-> pre-reload :c :stopped)) (-> @counter :c :stopped)))))) diff --git a/test/core/mount/test/parts.cljc b/test/core/mount/test/parts.cljc index 0a76a91..bed35d1 100644 --- a/test/core/mount/test/parts.cljc +++ b/test/core/mount/test/parts.cljc @@ -20,18 +20,18 @@ (f) (mount/stop))) -(use-fixtures :once +(use-fixtures :once #?(:cljs {:before #(mount/start #'tapp.conf/config #'tapp.audit-log/log) :after mount/stop} :clj with-parts)) #?(:clj - (deftest start-only-parts + (deftest start-only-parts (is (instance? datomic.peer.LocalConnection (dval conn))) (is (instance? mount.core.NotStartedState (dval should-not-start))))) #?(:cljs - (deftest start-only-parts + (deftest start-only-parts (is (instance? datascript.db/DB @(dval log))) (is (map? (dval config))) (is (instance? mount.core.NotStartedState (dval should-not-start))) diff --git a/test/core/mount/test/private_fun.cljc b/test/core/mount/test/private_fun.cljc index e487e54..03f37f7 100644 --- a/test/core/mount/test/private_fun.cljc +++ b/test/core/mount/test/private_fun.cljc @@ -9,11 +9,11 @@ #?(:clj (alter-meta! *ns* assoc ::load false)) -(use-fixtures :once +(use-fixtures :once #?(:cljs {:before #(mount/start #'mount.test.fun-with-values/private-f) :after mount/stop} - :clj #((mount/start #'mount.test.fun-with-values/private-f) - (%) + :clj #((mount/start #'mount.test.fun-with-values/private-f) + (%) (mount/stop)))) (deftest fun-with-values diff --git a/test/core/mount/test/start_with.cljc b/test/core/mount/test/start_with.cljc index 2e910d9..7a5ed4a 100644 --- a/test/core/mount/test/start_with.cljc +++ b/test/core/mount/test/start_with.cljc @@ -51,7 +51,7 @@ (is (instance? mount.core.NotStartedState (dval test-conn))) (is (instance? mount.core.NotStartedState (dval test-nrepl))) (mount/stop))))) - + #?(:clj (deftest start-with @@ -62,7 +62,7 @@ (is (= :nrepl-sub (dval nrepl))) (is (= "conn-sub" (dval conn))) (mount/stop))) - + (testing "should start normally after start-with" (let [_ (mount/start)] (is (map? (dval config))) diff --git a/test/core/mount/test/start_with_states.cljc b/test/core/mount/test/start_with_states.cljc index 7bde387..232753a 100644 --- a/test/core/mount/test/start_with_states.cljc +++ b/test/core/mount/test/start_with_states.cljc @@ -67,7 +67,7 @@ (is (instance? mount.core.NotStartedState (dval test-conn))) (is (instance? mount.core.NotStartedState (dval test-nrepl))) (mount/stop))))) - + #?(:clj (deftest start-with-states @@ -78,7 +78,7 @@ (is (instance? clojure.tools.nrepl.server.Server (dval nrepl))) (is (= (dval conn) 42)) (mount/stop))) - + #_(testing "should not start the substitute itself" ;; was true when subbing with exsiting states (let [_ (mount/start-with-states {#'tapp.nyse/conn swap-conn})] (is (instance? mount.core.NotStartedState (dval test-conn))) diff --git a/test/core/mount/test/start_without.cljc b/test/core/mount/test/start_without.cljc index a678e16..a13d325 100644 --- a/test/core/mount/test/start_without.cljc +++ b/test/core/mount/test/start_without.cljc @@ -20,7 +20,7 @@ (f) (mount/stop))) - (use-fixtures :once + (use-fixtures :once #?(:cljs {:before #(mount/start-without #'mount.test.helper/helper #'tapp.websockets/system-a) :after mount/stop} :clj without)) diff --git a/test/core/mount/test/stop_except.cljc b/test/core/mount/test/stop_except.cljc index 26fc54c..a61654f 100644 --- a/test/core/mount/test/stop_except.cljc +++ b/test/core/mount/test/stop_except.cljc @@ -25,7 +25,7 @@ (is (instance? mount.core.NotStartedState (dval config))) (is (instance? mount.core.NotStartedState (dval system-a))) (mount/stop))) - + (testing "should start normally after stop-except" (let [_ (mount/start)] (is (map? (dval config))) @@ -51,7 +51,7 @@ (is (instance? datomic.peer.LocalConnection (dval conn))) (is (instance? mount.core.NotStartedState (dval nrepl))) (mount/stop))) - + (testing "should start normally after stop-except" (let [_ (mount/start)] (is (map? (dval config)))