From 380c8b19c5fada55c40759063a4a23332bc7fdf8 Mon Sep 17 00:00:00 2001 From: David Nolen Date: Sat, 28 Mar 2015 13:29:01 -0400 Subject: [PATCH] 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 --- src/clj/cljs/core.clj | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/clj/cljs/core.clj b/src/clj/cljs/core.clj index a7891b5008..23918e78c9 100644 --- a/src/clj/cljs/core.clj +++ b/src/clj/cljs/core.clj @@ -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 @@ -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 {}) @@ -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