Skip to content

Instantly share code, notes, and snippets.

@darwin
Last active November 9, 2016 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darwin/34b2eaf97f1823b1180eb14ad64af9fd to your computer and use it in GitHub Desktop.
Save darwin/34b2eaf97f1823b1180eb14ad64af9fd to your computer and use it in GitHub Desktop.
nothing from this namespace is used anywhere, so `:advanced` build should elide everything (our goal)
; we cannot use cljs.core/merge because that would confuse advanced mode compilation
; if you look at cljs.core/merge you will see that it relies on protocol checks and this is too dymamic to be elided
(defn simple-merge [m1 m2]
(loop [m m1
ks (keys m2)]
(if (empty? ks)
m
(recur (assoc m (first ks) (get m2 (first ks))) (rest ks)))))
(def default-config defaults/prefs)
(def external-config (emit-external-config))
(def env-config (emit-env-config))
(def initial-config (simple-merge (simple-merge default-config external-config) env-config))
; we cannot use cljs.core/merge because that would confuse advanced mode compilation
; if you look at cljs.core/merge you will see that it relies on protocol checks and this is too dymamic to be elided
(defn simple-merge [m1 m2]
(loop [m m1
ks (keys m2)]
(if (empty? ks)
m
(recur (assoc m (first ks) (get m2 (first ks))) (rest ks)))))
(defn simple-merge2 [m1 m2]
(loop [m m1
ks (keys m2)]
(if (empty? ks)
m
(recur (assoc m (first ks) (get m2 (first ks))) (rest ks)))))
(def default-config defaults/prefs)
(def external-config (emit-external-config))
(def env-config (emit-env-config))
(def initial-config (simple-merge2 (simple-merge default-config external-config) env-config))
; we cannot use cljs.core/merge because that would confuse advanced mode compilation
; if you look at cljs.core/merge you will see that it relies on protocol checks and this is too dymamic to be elided
(defn simple-merge [m1 m2]
(loop [m m1
ks (keys m2)]
(if (empty? ks)
m
(recur (assoc m (first ks) (get m2 (first ks))) (rest ks)))))
(def default-config defaults/prefs)
(def external-config (emit-external-config))
(def env-config (emit-env-config))
(def initial-config (array (simple-merge default-config external-config) (simple-merge default-config env-config)))
; we cannot use cljs.core/merge because that would confuse advanced mode compilation
; if you look at cljs.core/merge you will see that it relies on protocol checks and this is too dymamic to be elided
(defn simple-merge [base-map & maps]
(let [rmaps (reverse maps)
extra-keys (dedupe (apply concat (map keys rmaps)))]
(loop [result base-map
ks extra-keys]
(if (empty? ks)
result
(let [key (first ks)
val (first (remove #{::not-found} (map #(get % key ::not-found) rmaps)))]
(recur (assoc result key val) (rest ks)))))))
(def default-config defaults/prefs)
(def external-config (emit-external-config))
(def env-config (emit-env-config))
(def initial-config (simple-merge default-config external-config env-config))
; we cannot use cljs.core/merge because that would confuse advanced mode compilation
; if you look at cljs.core/merge you will see that it relies on protocol checks and this is too dymamic to be elided
(defn simple-merge [base-map & maps]
(let [rmaps (reverse maps)
extra-keys (dedupe (apply concat (map keys rmaps)))]
(loop [result base-map
ks extra-keys]
(if (empty? ks)
result
(let [key (first ks)
val (first (mapcat #(let [v (get % key :not-found)]
(if-not (= v :not-found)
[v])) rmaps))]
(recur (assoc result key val) (rest ks)))))))
(def default-config defaults/prefs)
(def external-config (emit-external-config))
(def env-config (emit-env-config))
(def initial-config (simple-merge default-config external-config env-config))
; we cannot use cljs.core/merge because that would confuse advanced mode compilation
; if you look at cljs.core/merge you will see that it relies on protocol checks and this is too dymamic to be elided
(defn simple-merge [base-map & maps]
(let [rmaps (reverse maps)
extra-keys (dedupe (apply concat (map keys rmaps)))]
(loop [result base-map
ks extra-keys]
(if (empty? ks)
result
(let [key (first ks)
val (first (remove #{:not-found} (map #(get % key :not-found) rmaps)))]
(recur (assoc result key val) (rest ks)))))))
(def default-config defaults/prefs)
(def external-config (emit-external-config))
(def env-config (emit-env-config))
(def initial-config (simple-merge default-config external-config env-config))
; we cannot use cljs.core/merge because that would confuse advanced mode compilation
; if you look at cljs.core/merge you will see that it relies reduce which relieas on protocol checks and
; this is probably too dymamic to be elided (my theory)
(defn simple-merge [base-map & maps]
(let [rmaps (reverse maps)
sentinel (js-obj)
sentinel? #{sentinel}
merged-keys (dedupe (sort (apply concat (map keys rmaps))))]
(loop [result base-map
todo-keys merged-keys]
(if (empty? todo-keys)
result
(let [key (first todo-keys)
val (first (remove sentinel? (map #(get % key sentinel) rmaps)))]
(recur (assoc result key val) (rest todo-keys)))))))
(def default-config defaults/prefs)
(def external-config (emit-external-config))
(def env-config (emit-env-config))
(def initial-config (simple-merge default-config external-config env-config))
@darwin
Copy link
Author

darwin commented Nov 9, 2016

tested with ClojureScript 1.9.293

@darwin
Copy link
Author

darwin commented Nov 9, 2016

here is the final version binaryage/cljs-devtools@2b542a9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment