Given a library code that one wants to work in both the browser and node.js.
When it is using a browser specific API, that is available to node only through
a 3rd party package, how would you re-write this piece of code? Are nested defs
ok/bad/un-acceptable?
(if (exists? js/process)
(do
(def jsdom (.-jsdom (js/require "jsdom")))
(def jsdom-L1 (js/require "jsdom/lib/jsdom/level1/core"))
(def jsdom-L1-core (aget jsdom-L1 "dom" "level1" "core"))
(def Node (.-Node jsdom-L1-core))
(let [NodeList (.-NodeList jsdom-L1-core)
NamedNodeMap (.-NamedNodeMap jsdom-L1-core)
AttributeList (.-AttributeList jsdom-L1-core)]
(extend-type-with-seqable NodeList)
(extend-type-with-seqable NamedNodeMap)
(extend-type-with-seqable AttributeList)
(defn DOMParser-fromString
[s]
(jsdom s))))
(do
(extend-type-with-seqable js/NodeList)
(when (exists? js/NamedNodeMap)
(extend-type-with-seqable js/NamedNodeMap))
(when (exists? js/MozNamedAttrMap)
(extend-type-with-seqable js/MozNamedAttrMap))
(def Node js/Node)
(if (exists? js/DOMParser)
(defn DOMParser-fromString
[s]
(.parseFromString (js/DOMParser.) s "text/html"))
(def DOMParser-fromString nil))))
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.