Skip to content

Commit 4eebd45

Browse files
nopromptswannodette
authored andcommitted
CLJS-1144 - expose defaul-dispatch-val and dispatch-fn multifn accessors
1 parent 9d7ee61 commit 4eebd45

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/cljs/cljs/core.cljs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9242,7 +9242,9 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
92429242
(-prefer-method [mf dispatch-val dispatch-val-y])
92439243
(-get-method [mf dispatch-val])
92449244
(-methods [mf])
9245-
(-prefers [mf]))
9245+
(-prefers [mf])
9246+
(-default-dispatch-val [mf])
9247+
(-dispatch-fn [mf]))
92469248

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

94259427
(-methods [mf] @method-table)
94269428
(-prefers [mf] @prefer-table)
9429+
(-default-dispatch-val [mf] default-dispatch-val)
9430+
(-dispatch-fn [mf] dispatch-fn)
94279431

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

9468+
(defn default-dispatch-val
9469+
"Given a multimethod, return it's default-dispatch-val."
9470+
[multifn] (-default-dispatch-val multifn))
9471+
9472+
(defn dispatch-fn
9473+
"Given a multimethod, return it's dispatch-fn."
9474+
[multifn] (-dispatch-fn multifn))
9475+
94649476
;; UUID
94659477

94669478
(deftype UUID [uuid]

test/cljs/cljs/core_test.cljs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,13 @@
27142714
(is (= 12345 (:baz m)))
27152715
(is (= "String Metadata" (:whatever m)))))
27162716

2717+
(defmulti cljs-1144 identity :default ::default)
2718+
2719+
(deftest test-cljs-1144
2720+
(is (not= map (dispatch-fn cljs-1144)))
2721+
(is (= identity (dispatch-fn cljs-1144)))
2722+
(is (= ::default (default-dispatch-val cljs-1144))))
2723+
27172724
(comment
27182725
;; ObjMap
27192726
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)