helix

JonR 2021-09-03T16:16:51.043700Z

Hey @lilactown, thanks for the library! We're building our new app on helix and loving it so far. Something I've been wondering about a bit is if helix and the component macro + hook wrappers could allow for exposing more info around re-renders triggered by hooks. Unless I'm unaware of some new tools, this has been a major pain point in optimizing vanilla js(x) react components. My understanding is that the way react has implemented hooks fundamentally is at odds with surfacing this info via the debugger. Any thoughts on if it would be useful, and if so, how hard to expose this type of info. For example, if you could pass a meta data flag and handler to a component which is called with component name and hook name that returned a new value.

lilactown 2021-09-03T16:24:19.044200Z

hmm, so the "want" is to be able to know what triggered a specific render?

lilactown 2021-09-03T16:25:34.044900Z

i.e. "this render was triggered by this specific use-state hook by calling set-state with arguments xyz "?

lilactown 2021-09-03T16:35:28.045700Z

I guess if you just want to know what values have changed, you could use something like https://github.com/clj-commons/spyscope

JonR 2021-09-03T16:37:28.046300Z

yes @lilactown, that is the "want". Checking out spyscope now

lilactown 2021-09-03T16:37:47.046700Z

or debux: https://github.com/philoskim/debux

lilactown 2021-09-03T16:37:53.047100Z

i seem to recall a bunch of libs like this

JonR 2021-09-03T16:38:24.047300Z

nice, I haven't seen either of these

lilactown 2021-09-03T16:39:17.047900Z

anyway, I could imagine a macro or something similar to what these provide but only logs things when values change from previous

JonR 2021-09-03T16:39:27.048400Z

yup, exactly what I was thinking about

JonR 2021-09-03T16:39:51.049200Z

That + the context of which component you're in would do it I think

lilactown 2021-09-03T16:39:52.049300Z

if you do it as a macro or reader tag, you can use the ns+line as the identity to trace things across renders

lilactown 2021-09-03T16:40:25.049700Z

which would mean you wouldn't need to do anything with helix 🙂

JonR 2021-09-03T16:40:56.049900Z

💥

JonR 2021-09-03T16:41:13.050300Z

ok nice, I'll mess around with this sort of approach. Thanks for the tips and thoughts

JonR 2021-09-03T16:41:48.051300Z

In part, I think it's just something you could do with cljs and not js so would be fun to show

lilactown 2021-09-03T16:41:53.051500Z

sure thing. I'm inspired. would be interested in something like this for my own debugging purposes

lilactown 2021-09-03T16:41:58.051700Z

yeah!

JonR 2021-09-03T16:42:13.052200Z

If I get something interesting going I'll loop back around

🙏🏻 1
JonR 2021-09-03T16:42:24.052500Z

Oh yeah, while I have you, one other quick question

JonR 2021-09-03T16:42:47.053100Z

Any thoughts on allowing use-callback to take a fn var rather then need a body?

lilactown 2021-09-03T16:43:16.053700Z

ugghh yes. I should start that effort sooner rather than later

JonR 2021-09-03T16:43:35.054100Z

It's not a blocker or anything, just curious if there was an explicit reason to disallow

lilactown 2021-09-03T16:46:39.055500Z

actually, backing up, because I was thinking of use-memo and use-effect: you're finding you can't pass in a var to use-callback? i.e.

(use-callback
  :once
  some-fn)
doesn't work?

JonR 2021-09-03T16:47:23.056100Z

I thought so but your question makes me doubt my question 🙂. Checking now

JonR 2021-09-03T16:48:38.056400Z

_ (hooks/use-callback
           []
           update-query-params)

JonR 2021-09-03T16:48:59.056700Z

--------------------------------------------------------------------------------
 183 | 
 184 |         search-terms (get query-params :search-terms "")
 185 | 
 186 |         _ (hooks/use-callback
-----------------^--------------------------------------------------------------
 Got a single symbol update-query-params as a body, expected an expression. Maybe you meant (update-query-params)?
--------------------------------------------------------------------------------
 187 |            []
 188 |            update-query-params)
 189 | 
 190 |         debounce-time 325
--------------------------------------------------------------------------------

JonR 2021-09-03T16:49:12.057Z

there's what I get in the shadow build

lilactown 2021-09-03T16:49:45.057400Z

I see. ty for the report! I believe that warning is wrong

lilactown 2021-09-03T16:49:55.057700Z

it's true for use-memo but not for use-callback

JonR 2021-09-03T16:50:03.058Z

Happy to create an issue if that's helpful

JonR 2021-09-03T16:51:01.058300Z

But doh, now I see it is valid just warning

lilactown 2021-09-03T16:53:26.058600Z

yeah but warnings can block hot reloading in some setups

lilactown 2021-09-03T16:53:31.058800Z

I'll put a fix out for this

JonR 2021-09-03T16:53:35.059Z

thanks!

lilactown 2021-09-03T18:52:06.060100Z

I just published helix 0.1.2 with the following: Fixed • Fix invalid hooks check false warnings when a `use-` symbol appears in a quoted form (@SevereOverfl0w) • Allow a single var/binding to be passed to `use-callback` Added • Invalid hooks check now happens in `defhook` forms • fnc for constructing anonymous components https://github.com/lilactown/helix/blob/master/CHANGELOG.md

💥 3
🎉 5