-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: use macro #17
Comments
One thing to consider is this would conflict with CLJS.core/use and also editors may not indent it nicely by default. |
An alternative proposal:
Examples: ; using a built-in hook
(with-deps :auto
(hooks/use-memo
(foo)))
; using a custom hook is no different
(with-deps [dep1 dep2]
(use-my-custom-hook
(foo)))
; implementing a custom hook
(defn ^:helix/hook use-my-custom-hook [deps f]
(let [new-deps (concat deps [dep3 dep4])]
(with-deps new-deps
(hooks/use-effect
(f)))))
; what if somebody does this?
(with-deps :auto
(println "some arbitrary code")
(hooks/use-memo
(foo d1))
(println "some other code")
(hooks/use-effect
(bar d2 d3))) Let's discuss the last example. TL;DR; it should still work.
Each use-hook call will be rewritten, like in the current implementation (including optional code analysis). Explicit deps or auto-inferred deps will be passed in as the first arg. So the above example would rewrite roughly to something like: (do
(println "some arbitrary code")
(hooks/use-memo
#js [d1]
(fn [] (foo d1)))
(println "some other code")
(hooks/use-effect
#js [d2 d3]
(fn [] (bar d2 d3))) DrawbacksIf user forgets to wrap hook call in
Alternatively instead:
Further ideas
|
I like the idea of moving hooks deps detection to the I have been working on code analysis inside I think I am less bullish on the auto-deps functionality than I was before. I am more interested in detecting when deps are not filled in fully, and warning (with the ability to ignore). I am fine with not extending |
One problem with the use-memo / use-effect / et al. macros is that their static analysis does not extend to custom hooks.
For instance, you cannot define a custom hook that uses the
:auto-deps
functionality without creating a macro and using some internal functions of helix.The proposal here is to introduce a new macro (or two) with semantics that would allow users to define custom hooks that benefit from helix's static analysis.
Custom hooks could be defined using a
defhook
macro that could annotate the symbol with info about whether it takes deps or not.The text was updated successfully, but these errors were encountered: