Has anyone seen a strange reagent.core/with-let
behavior where it just swallows some exception and keeps going as if the rest of the bindings were all set to undefined
?
I can see it in a fairly complex app but I'm struggling to reproduce it in a simple setup at the moment.
Came up with an MRE, created https://github.com/reagent-project/reagent/issues/525
2Sorry for the confusion... "If you want optional arguments, you can use multi-arities or a map with optional keys. That's all I can say right now." Actually the multi arity is what I'm trying to avoid, because then I have to check if the first param is map (meaning its a props), otherwise its a child, and if second param also has value, then I have to combine first and second param as child. Lets say if I made it this way..
(defn text [props & children])
;; props is "Hey", children is nil
[text "Hey"]
;; props is map, children is (("Hey"))
[text {:style {:fontSize 16}} "Hey"]
;; props is map, children is ([text "Hey"])
[text {:style {:fontSize 16}} [text "Hey"]]
;; props is [text "Child 1"], children is ([text "Child 2"])
[text [text "Child 1"] [text "Child 2"]]
;; props is map, children list of [text]
[text
{:style {:color "red"}}
[text "with color Child 1"]
[text "with color child 2"]]
In the above example, I have to handle inconsistency of the params (props and children) if I will be using the function params. And what I'm trying to point out is, its better not to use the params, and just rely on (r/props) and (r/children) to get consistency. (Consistency here meaning, props will always be a map, and first children will not be in the props
function param in cases I did not pass style map in the component), reagent knows it is a children
You don't have to check anything if you don't have the same arity that accepts different types:
(defn my-view
([arg] ...)
([arg1 arg2] ...))
But it won't work if you want to be able to accept varargs.
And if you do want that, you have pretty much outlined the available options yourself.