#23: cleanup up most of AOT cljs warnings.. [still have some]

This commit is contained in:
anatoly 2015-12-15 09:41:09 -05:00
parent dc5b6c2614
commit c1be3c377e
5 changed files with 43 additions and 49 deletions

1
.gitignore vendored
View file

@ -7,6 +7,7 @@ pom.xml.asc
dev/resources/public/js/*
figwheel_server.log
build.xml
doo-index.html
*.jar
*.class
/.lein-*

View file

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

View file

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

View file

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

View file

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