Skip to content

Instantly share code, notes, and snippets.

@jolby
Created August 6, 2011 23:31
Show Gist options
  • Save jolby/1129881 to your computer and use it in GitHub Desktop.
Save jolby/1129881 to your computer and use it in GitHub Desktop.
Working load-externs function for closure.clj (Clojurescript)
(defn load-externs
"Externs are JavaScript files which contain empty definitions of
functions which will be provided by the environment. Any function in
an extern file will not be renamed during optimization.
Options may contain an :externs key with a list of file paths to
load. The :use-only-custom-externs flag may be used to indicate that
the default externs should be excluded."
[opts]
(let [jsf #(js-source-file % (io/input-stream (io/resource %)))
default (if (:use-only-custom-externs opts) [] (vec (CommandLineRunner/getDefaultExterns)))
externs (if (:externs opts) (vec (concat default (map #(jsf %) (:externs opts)))) default)]
(if (= :nodejs (:target opts))
(conj externs (jsf "cljs/nodejs_externs.js"))
externs)))
cljs.closure> (load-externs {})
[#<JSSourceFile externs.zip//es3.js> #<JSSourceFile externs.zip//es5.js> #<JSSourceFile externs.zip//w3c_event.js> #<JSSourceFile externs.zip//w3c_event3.js> #<JSSourceFile externs.zip//gecko_event.js> #<JSSourceFile externs.zip//ie_event.js> #<JSSourceFile externs.zip//webkit_event.js> #<JSSourceFile externs.zip//w3c_dom1.js> #<JSSourceFile externs.zip//w3c_dom2.js> #<JSSourceFile externs.zip//w3c_dom3.js> #<JSSourceFile externs.zip//gecko_dom.js> #<JSSourceFile externs.zip//ie_dom.js> #<JSSourceFile externs.zip//webkit_dom.js> #<JSSourceFile externs.zip//w3c_css.js> #<JSSourceFile externs.zip//gecko_css.js> #<JSSourceFile externs.zip//ie_css.js> #<JSSourceFile externs.zip//webkit_css.js> #<JSSourceFile externs.zip//google.js> #<JSSourceFile externs.zip//deprecated.js> #<JSSourceFile externs.zip//fileapi.js> #<JSSourceFile externs.zip//flash.js> #<JSSourceFile externs.zip//gears_symbols.js> #<JSSourceFile externs.zip//gears_types.js> #<JSSourceFile externs.zip//gecko_xml.js> #<JSSourceFile externs.zip//html5.js> #<JSSourceFile externs.zip//ie_vml.js> #<JSSourceFile externs.zip//iphone.js> #<JSSourceFile externs.zip//webstorage.js> #<JSSourceFile externs.zip//w3c_css3d.js> #<JSSourceFile externs.zip//w3c_elementtraversal.js> #<JSSourceFile externs.zip//w3c_geolocation.js> #<JSSourceFile externs.zip//w3c_indexeddb.js> #<JSSourceFile externs.zip//w3c_range.js> #<JSSourceFile externs.zip//w3c_selectors.js> #<JSSourceFile externs.zip//w3c_xml.js> #<JSSourceFile externs.zip//window.js> #<JSSourceFile externs.zip//webkit_notifications.js> #<JSSourceFile externs.zip//webgl.js>]
cljs.closure> (load-externs {:target :nodejs :externs ["cljs/externs/Ti-1.7.2.js"]})
[#<JSSourceFile externs.zip//es3.js> #<JSSourceFile externs.zip//es5.js> #<JSSourceFile externs.zip//w3c_event.js> #<JSSourceFile externs.zip//w3c_event3.js> #<JSSourceFile externs.zip//gecko_event.js> #<JSSourceFile externs.zip//ie_event.js> #<JSSourceFile externs.zip//webkit_event.js> #<JSSourceFile externs.zip//w3c_dom1.js> #<JSSourceFile externs.zip//w3c_dom2.js> #<JSSourceFile externs.zip//w3c_dom3.js> #<JSSourceFile externs.zip//gecko_dom.js> #<JSSourceFile externs.zip//ie_dom.js> #<JSSourceFile externs.zip//webkit_dom.js> #<JSSourceFile externs.zip//w3c_css.js> #<JSSourceFile externs.zip//gecko_css.js> #<JSSourceFile externs.zip//ie_css.js> #<JSSourceFile externs.zip//webkit_css.js> #<JSSourceFile externs.zip//google.js> #<JSSourceFile externs.zip//deprecated.js> #<JSSourceFile externs.zip//fileapi.js> #<JSSourceFile externs.zip//flash.js> #<JSSourceFile externs.zip//gears_symbols.js> #<JSSourceFile externs.zip//gears_types.js> #<JSSourceFile externs.zip//gecko_xml.js> #<JSSourceFile externs.zip//html5.js> #<JSSourceFile externs.zip//ie_vml.js> #<JSSourceFile externs.zip//iphone.js> #<JSSourceFile externs.zip//webstorage.js> #<JSSourceFile externs.zip//w3c_css3d.js> #<JSSourceFile externs.zip//w3c_elementtraversal.js> #<JSSourceFile externs.zip//w3c_geolocation.js> #<JSSourceFile externs.zip//w3c_indexeddb.js> #<JSSourceFile externs.zip//w3c_range.js> #<JSSourceFile externs.zip//w3c_selectors.js> #<JSSourceFile externs.zip//w3c_xml.js> #<JSSourceFile externs.zip//window.js> #<JSSourceFile externs.zip//webkit_notifications.js> #<JSSourceFile externs.zip//webgl.js> #<JSSourceFile cljs/externs/Ti-1.7.2.js> #<JSSourceFile cljs/nodejs_externs.js>]
cljs.closure> (load-externs {:use-only-custom-externs true :externs ["cljs/externs/Ti-1.7.2.js"]})
[#<JSSourceFile cljs/externs/Ti-1.7.2.js>]
cljs.closure> (load-externs {:use-only-custom-externs true :target :nodejs :externs ["cljs/externs/Ti-1.7.2.js"]})
[#<JSSourceFile cljs/externs/Ti-1.7.2.js> #<JSSourceFile cljs/nodejs_externs.js>]
cljs.closure> (load-externs {:use-only-custom-externs true :target :nodejs :externs ["cljs/externs/Ti-1.7.2.js"]})
[#<JSSourceFile cljs/externs/Ti-1.7.2.js> #<JSSourceFile cljs/nodejs_externs.js>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment