Skip to content

Commit

Permalink
CLJS-1175: CLJS defmulti doesn't exhibit same defonce behavior as Clo…
Browse files Browse the repository at this point in the history
…jure's defmulti, suggesting an even better reloading behavior

defmulti now expands to defonce not def

add ns-unmap macro to support interactions with defonce
  • Loading branch information
swannodette committed Mar 28, 2015
1 parent 1cc1818 commit 380c8b1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/clj/cljs/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

cond-> cond->> as-> some-> some->>

if-some when-some test ns-interns var vswap! macroexpand-1 macroexpand])
if-some when-some test ns-interns ns-unmap var vswap! macroexpand-1 macroexpand])
(:require clojure.walk
clojure.set
cljs.compiler
Expand Down Expand Up @@ -1855,7 +1855,7 @@
(let [options (apply core/hash-map options)
default (core/get options :default :default)]
(check-valid-options options :default :hierarchy)
`(def ~(with-meta mm-name m)
`(defonce ~(with-meta mm-name m)
(let [method-table# (atom {})
prefer-table# (atom {})
method-cache# (atom {})
Expand Down Expand Up @@ -1962,6 +1962,15 @@
`[(symbol ~(name sym)) (var ~(symbol (name ns) (name sym)))])
(get-in @env/*compiler* [:cljs.analyzer/namespaces ns :defs]))]))

(defmacro ns-unmap
"Removes the mappings for the symbol from the namespace."
[[quote0 ns] [quote1 sym]]
(core/assert (core/and (= quote0 'quote) (core/symbol? ns)
(= quote1 'quote) (core/symbol? sym))
"Arguments to ns-unmap must be quoted symbols")
(swap! env/*compiler* update-in [::ana/namespaces ns :defs] dissoc sym)
`(js-delete ~(cljs.compiler/munge ns) ~(cljs.compiler/munge (core/str sym))))

(defmacro vswap!
"Non-atomically swaps the value of the volatile as if:
(apply f current-value-of-vol args). Returns the value that
Expand Down

0 comments on commit 380c8b1

Please sign in to comment.