Skip to content

Commit

Permalink
CLJS-1144 - expose defaul-dispatch-val and dispatch-fn multifn accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
noprompt authored and swannodette committed Mar 27, 2015
1 parent 9d7ee61 commit 4eebd45
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9242,7 +9242,9 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
(-prefer-method [mf dispatch-val dispatch-val-y])
(-get-method [mf dispatch-val])
(-methods [mf])
(-prefers [mf]))
(-prefers [mf])
(-default-dispatch-val [mf])
(-dispatch-fn [mf]))

(defn- throw-no-method-error [name dispatch-val]
(throw (js/Error. (str "No method in multimethod '" name "' for dispatch value: " dispatch-val))))
Expand Down Expand Up @@ -9424,6 +9426,8 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."

(-methods [mf] @method-table)
(-prefers [mf] @prefer-table)
(-default-dispatch-val [mf] default-dispatch-val)
(-dispatch-fn [mf] dispatch-fn)

INamed
(-name [this] (-name name))
Expand Down Expand Up @@ -9461,6 +9465,14 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
"Given a multimethod, returns a map of preferred value -> set of other values"
[multifn] (-prefers multifn))

(defn default-dispatch-val
"Given a multimethod, return it's default-dispatch-val."
[multifn] (-default-dispatch-val multifn))

(defn dispatch-fn
"Given a multimethod, return it's dispatch-fn."
[multifn] (-dispatch-fn multifn))

;; UUID

(deftype UUID [uuid]
Expand Down
7 changes: 7 additions & 0 deletions test/cljs/cljs/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2714,6 +2714,13 @@
(is (= 12345 (:baz m)))
(is (= "String Metadata" (:whatever m)))))

(defmulti cljs-1144 identity :default ::default)

(deftest test-cljs-1144
(is (not= map (dispatch-fn cljs-1144)))
(is (= identity (dispatch-fn cljs-1144)))
(is (= ::default (default-dispatch-val cljs-1144))))

(comment
;; ObjMap
;; (let [ks (map (partial str "foo") (range 500))
Expand Down

0 comments on commit 4eebd45

Please sign in to comment.