Fork me on GitHub
#clojurescript
<
2019-09-14
>
lepistane09:09:42

hi guys i am using google maps in my cljs app and i am creating info windows for my markers https://developers.google.com/maps/documentation/javascript/infowindows in this example they are passing content as string which i kinda don't like so i wanted to create hiccup->html fn but i suppose there are libraries for that the only one i found was https://github.com/davidsantiago/hickory but i am unsure if approach is good. Are there any better solutions that i am not aware of?

Quest20:09:14

I want to do an "autodetection" mechanism in my library to load implementation only if a requisite namespace exists on the classpath, but I hit this in my CLJS tests: Calls to 'require' must appear at the top-level

(defn- datomic-exists? [] (boolean (find-ns 'datomic.api)))
(defn- datascript-exists? [] (boolean (find-ns 'datascript.db)))

(defn- require-implementations
  []
  (when (datomic-exists?)
    (require '[northstar.model.database.datomic]))
  (when (datascript-exists?)
    (require '[northstar.model.database.datascript])))
Is there a way to do this sort of auto-detection in CLJS? As a workaround, I believe I could: A) use CLJC macros & make CLJS library consumers manually require the implementation ns northstar.model.database.datascript B) just assume CLJS clients have already included DataScript & hardwire the require in (this assumption holds true for all current consumers)

andy.fingerhut20:09:02

Others will be able to answer more authoritative (and I am curious to hear an answer from someone with more in-depth knowledge, too, to confirm), but CLJS is a bit less dynamic than CLJ in this way.

Quest20:09:55

figured as much, but wondered if there was some secret sauce I didn't know about. I ended up going with B -- can someday swap to A if a consumer doesn't want the DataScript dependency

(ns northstar.model.database.api
  (:require ...
            #?(:cljs [northstar.model.database.datascript])))