helix

https://github.com/Lokeh/helix
alidlorenzo 2020-01-14T16:50:31.002Z

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 

alidlorenzo 2020-01-14T16:51:13.002500Z

by possible I mean whether you considered that at all but decided against it due to certain trade-offs

alidlorenzo 2020-01-14T16:51:38.002700Z

@lilactown

lilactown 2020-01-14T18:41:00.005400Z

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

lilactown 2020-01-14T18:43:42.006400Z

so I decided to punt on that decision for now. you can do this easily via:

(defnc View [props]
  ...)

(def view (helix/factory View))

alidlorenzo 2020-01-14T18:50:44.009100Z

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

lilactown 2020-01-14T18:55:13.010900Z

you can’t return a macro, unfortunately. and $ needs the map to be written out literally in order to convert props at compile-time

👍 1
lilactown 2020-01-14T18:56:45.012500Z

($ 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 {}

lilactown 2020-01-14T18:58:15.013600Z

one thing it could do is something like: defnc View will automatically define a constructor function, ->View or something

alidlorenzo 2020-01-14T18:59:39.014200Z

can you expand on that last point?

alidlorenzo 2020-01-14T19:04:50.015300Z

and so yea, converting the props at compile time seems to be the issue, thanks for clarifying