Skip to content

Commit 380c8b1

Browse files
committed
CLJS-1175: CLJS defmulti doesn't exhibit same defonce behavior as Clojure's defmulti, suggesting an even better reloading behavior
defmulti now expands to defonce not def add ns-unmap macro to support interactions with defonce
1 parent 1cc1818 commit 380c8b1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/clj/cljs/core.clj

+11-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
cond-> cond->> as-> some-> some->>
3636

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

1965+
(defmacro ns-unmap
1966+
"Removes the mappings for the symbol from the namespace."
1967+
[[quote0 ns] [quote1 sym]]
1968+
(core/assert (core/and (= quote0 'quote) (core/symbol? ns)
1969+
(= quote1 'quote) (core/symbol? sym))
1970+
"Arguments to ns-unmap must be quoted symbols")
1971+
(swap! env/*compiler* update-in [::ana/namespaces ns :defs] dissoc sym)
1972+
`(js-delete ~(cljs.compiler/munge ns) ~(cljs.compiler/munge (core/str sym))))
1973+
19651974
(defmacro vswap!
19661975
"Non-atomically swaps the value of the volatile as if:
19671976
(apply f current-value-of-vol args). Returns the value that

0 commit comments

Comments
 (0)