In Respo I defined a component like this:
(defn render [text on-click]
(fn [state mutate]
(div {:style {:background-color (hsl 200 80 70)
:display "inline-block"
:padding "0 8px"
:color "white"
:margin "0 8px"
:cursor "pointer"}
:event {:click on-click}}
(span {:attrs {:inner-text text}}))))
but the implementation of render function has to support arbitrary number of arguments, so I used apply render args
here:
defn render-component
markup states build-mutate coord
let
(begin-time $ io-get-time)
args $ :args markup
component $ first markup
init-state $ :init-state markup
new-coord $ conj coord (:name markup)
state $ if (contains? states new-coord)
get states new-coord
apply init-state args
render $ :render markup
half-render $ apply render args
mutate $ build-mutate new-coord
markup-tree $ half-render state mutate
tree $ render-element markup-tree states build-mutate new-coord new-coord
cost $ - (io-get-time)
, begin-time
-- .log js/console "|markup tree:" $ pr-str markup-tree
assoc markup :coord coord :tree tree :cost cost
then I can use this to create the component:
(comp-button "inc" handle-click)
but I found type checking is not available here, probably because I used apply
. Is the any way to fix it?