From c4096849546645226984d02a19b896a04f77501b Mon Sep 17 00:00:00 2001 From: Chris Zheng Date: Fri, 9 Jun 2017 12:54:25 +1000 Subject: [PATCH] changed react-fn to a multimethod --- src/sablono/util.cljc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/sablono/util.cljc b/src/sablono/util.cljc index 68c9801..e0818e0 100644 --- a/src/sablono/util.cljc +++ b/src/sablono/util.cljc @@ -68,12 +68,14 @@ (remove nil?))) (str/join " "))) -(defn react-fn +(defmulti react-fn "Return the symbol of a fn that build a React element. " - [type] - (if (contains? #{:input :select :textarea} (keyword type)) - 'sablono.interpreter/create-element - 'js/React.createElement)) + (fn [type] (keyword type))) + +(defmethod react-fn :input [_] 'sablono.interpreter/create-element) +(defmethod react-fn :select [_] 'sablono.interpreter/create-element) +(defmethod react-fn :textarea [_] 'sablono.interpreter/create-element) +(defmethod react-fn :default [_] 'js/React.createElement) #?(:cljs (extend-protocol ToString