would it be possible to make components themselves callable (without the $ macro) when you initialize them with defnc
?
i.e. been playing around with hypersrcipt in Javascript, settled upon this API:
const customView = h(props => view(props))
customView() // `h` wraps the component in createElement so it can be callable
by possible I mean whether you considered that at all but decided against it due to certain trade-offs
I have thought about it. Assuming you can executed it like (custom-view {:foo "bar"})
, there are two cons that I ran into:
1. Because it’s a function (not a macro), it would allocate a new map and then have to parse that into a JS object to pass to the React component each render
2. Because it’s a function (not a macro), it would have slightly different syntax than the helix.dom
macros which I thought mayyyybe might be confusing? unsure
so I decided to punt on that decision for now. you can do this easily via:
(defnc View [props]
...)
(def view (helix/factory View))
may be a minor grievance, but for every component having two declarations seems unnecessarily tedious, so wondering how to go around that
couldn't the function be treated as a macro? like rather than defnc
returning a component that can be used rendered by $
, defnc
can return a component already wrapped in by $
logic and so calling it renders it
you can’t return a macro, unfortunately. and $
needs the map to be written out literally in order to convert props at compile-time
($ View {:foo "bar"})
will emit (React.createElement View #js {:foo "bar"})
if $
doesn’t know the map passed into it at compile time, it cannot rewrite the {}
into a #js {}
one thing it could do is something like: defnc View
will automatically define a constructor function, ->View
or something
can you expand on that last point?
and so yea, converting the props at compile time seems to be the issue, thanks for clarifying