reformat all with linter

This commit is contained in:
anatoly 2018-03-15 23:50:42 -04:00
parent e032a6ef54
commit e247636be6
28 changed files with 70 additions and 70 deletions

View file

@ -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"))

View file

@ -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

View file

@ -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)))

View file

@ -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)))

View file

@ -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}))))

View file

@ -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])))

View file

@ -12,7 +12,7 @@
" &#8594; [" (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)]))])))

View file

@ -1,4 +1,4 @@
{:datomic
{:datomic
{:uri "datomic:mem://mount"}
:www {:port 4242}

View file

@ -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_"

View file

@ -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"]

View file

@ -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]

View file

@ -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"))

View file

@ -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)))

View file

@ -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)))

View file

@ -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])))

View file

@ -12,7 +12,7 @@
" &#8594; [" (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)]))])))

View file

@ -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)

View file

@ -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))))))

View file

@ -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

View file

@ -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))))

View file

@ -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

View file

@ -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))))))

View file

@ -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)))

View file

@ -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

View file

@ -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)))

View file

@ -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)))

View file

@ -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))

View file

@ -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)))