diff --git a/.gitignore b/.gitignore index 1f14e58..a215468 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ pom.xml.asc dev/resources/public/js/* figwheel_server.log build.xml +doo-index.html *.jar *.class /.lein-* diff --git a/project.clj b/project.clj index f855e29..9d424ae 100644 --- a/project.clj +++ b/project.clj @@ -10,7 +10,7 @@ :profiles {:dev {:source-paths ["dev" "dev/clj"] :dependencies [[org.clojure/clojure "1.7.0"] - [org.clojure/clojurescript "1.7.170"] + [org.clojure/clojurescript "1.7.170"]; :classifier "aot"] [datascript "0.13.3"] [hiccups "0.3.0"] [com.andrewmcveigh/cljs-time "0.3.14"] diff --git a/src/mount/core.cljc b/src/mount/core.cljc index 5b54fc4..a78353e 100644 --- a/src/mount/core.cljc +++ b/src/mount/core.cljc @@ -1,9 +1,8 @@ (ns mount.core #?(:clj (:require [mount.tools.macro :refer [on-error throw-runtime] :as macro]) - :cljs (:require [mount.tools.macro :as macro] - [mount.tools.cljs :as cljs])) - #?(:cljs (:require-macros [mount.tools.macro :refer [on-error throw-runtime]] - [mount.core :refer [defstate]]))) + :cljs (:require [mount.tools.macro :as macro])) + #?(:cljs (:require-macros [mount.core] + [mount.tools.macro :refer [on-error throw-runtime]]))) (defonce ^:private -args (atom :no-args)) ;; mostly for command line args and external files (defonce ^:private state-seq (atom 0)) @@ -35,13 +34,12 @@ (str "#'" ns "/" name)) (defn- pounded? [f] - (let [pound "(fn* [] "] ;;TODO: think of a better (i.e. typed) way to distinguish #(f params) from (fn [params] (...))) - #?(:clj (.startsWith (str f) pound) - :cljs (cljs/starts-with? (str f) pound)))) + (let [pound "(fn* [] "] ;;TODO: think of a better (i.e. typed) way to distinguish #(f params) from (fn [params] (...))) + (.startsWith (str f) pound))) (defn unpound [f] (if (pounded? f) - (nth f 2) ;; magic 2 is to get the body => ["fn*" "[]" "(fn body)"] + (nth f 2) ;; magic 2 is to get the body => ["fn*" "[]" "(fn body)"] f)) (defn- cleanup-if-dirty @@ -128,25 +126,26 @@ (up name state (atom #{}))) @inst))) -(defmacro defstate [state & body] - (let [[state params] (macro/name-with-attributes state body) - {:keys [start stop suspend resume] :as lifecycle} (apply hash-map params) - state-name (with-ns *ns* state) - order (make-state-seq state-name) - sym (str state)] - (validate lifecycle) - (cleanup-if-dirty state-name) - (let [s-meta (cond-> {:order order - :start `(fn [] ~start) - :status #{:stopped}} - stop (assoc :stop `(fn [] ~stop)) - suspend (assoc :suspend `(fn [] ~suspend)) - resume (assoc :resume `(fn [] ~resume)))] - `(do - (def ~state (DerefableState. ~state-name)) - ((var update-meta!) [~state-name] (assoc ~s-meta :inst (atom (NotStartedState. ~state-name)) - :var (var ~state))) - (var ~state))))) +#?(:clj + (defmacro defstate [state & body] + (let [[state params] (macro/name-with-attributes state body) + {:keys [start stop suspend resume] :as lifecycle} (apply hash-map params) + state-name (with-ns *ns* state) + order (make-state-seq state-name) + sym (str state)] + (validate lifecycle) + (cleanup-if-dirty state-name) + (let [s-meta (cond-> {:order order + :start `(fn [] ~start) + :status #{:stopped}} + stop (assoc :stop `(fn [] ~stop)) + suspend (assoc :suspend `(fn [] ~suspend)) + resume (assoc :resume `(fn [] ~resume)))] + `(do + (def ~state (DerefableState. ~state-name)) + ((var update-meta!) [~state-name] (assoc ~s-meta :inst (atom (NotStartedState. ~state-name)) + :var (var ~state))) + (var ~state)))))) (defn in-cljc-mode [] (reset! mode :cljc)) @@ -182,7 +181,7 @@ #?(:cljs (defn var-to-str [v] - (if (var? v) + (if (instance? cljs.core.Var v) (let [{:keys [ns name]} (meta v)] (with-ns ns name)) v))) diff --git a/src/mount/tools/cljs.cljs b/src/mount/tools/cljs.cljs deleted file mode 100644 index 35f1fc3..0000000 --- a/src/mount/tools/cljs.cljs +++ /dev/null @@ -1,9 +0,0 @@ -(ns mount.tools.cljs - (:require [cljs.analyzer :as ana] - [goog.string :as gstring])) - -(defn this-ns [] - ana/*cljs-ns*) - -(defn starts-with? [s pre] - (gstring/startsWith s pre)) diff --git a/src/mount/tools/macro.cljc b/src/mount/tools/macro.cljc index 22961aa..7177726 100644 --- a/src/mount/tools/macro.cljc +++ b/src/mount/tools/macro.cljc @@ -1,16 +1,19 @@ -(ns mount.tools.macro) +(ns mount.tools.macro + #?(:cljs (:require-macros [mount.tools.macro]))) -(defmacro on-error [msg f] - `(try - ~f - (catch #?(:clj Throwable - :cljs :default) t# - (throw #?(:clj (RuntimeException. ~msg t#) - :cljs (js/Error (str ~msg (.-stack t#)))))))) +#?(:clj + (defmacro on-error [msg f] + `(try + ~f + (catch #?(:clj Throwable + :cljs :default) t# + (throw #?(:clj (RuntimeException. ~msg t#) + :cljs (js/Error (str ~msg (.-stack t#))))))))) -(defmacro throw-runtime [msg] - `(throw #?(:clj (RuntimeException. ~msg) - :cljs (js/Error (str ~msg))))) +#?(:clj + (defmacro throw-runtime [msg] + `(throw #?(:clj (RuntimeException. ~msg) + :cljs (js/Error (str ~msg)))))) ;; this is a one to one copy from https://github.com/clojure/tools.macro ;; to avoid a lib dependency for a single function