helix

kennytilton 2021-07-12T07:39:44.170600Z

I am leaning towards making Helix the basis of my new CLJS+RN library based on my own state management library, and I am still wrapping my head around RN itself so this may be wrong, but I think I need to use some form of create-class to be able to force updates when my state management lib sees the need. This doc is great https://github.com/lilactown/helix/blob/master/docs/creating-components.md but ends up with class components as "WIP". Is there any progress on that? I will keep staring at RN to see if a supervising engine can force the re-render of functional components -- hints welcome! 🙏

lilactown 2021-07-12T16:53:45.171600Z

hey kenny! i'll read through the issue you created and your comments on helix-todo-mvc this afternoon.

lilactown 2021-07-12T16:54:42.172400Z

I will reply re: classes- with hooks, you should not need classes except if you are trying to build an https://reactjs.org/docs/error-boundaries.htmly

lilactown 2021-07-12T16:55:21.173300Z

there's a macro for defining classes called defcomponent in helix.core but I just haven't documented it

lilactown 2021-07-12T17:00:58.177900Z

the way that you would have your state management lib trigger a render is by using a custom hook in the body of the component listening to the observable that updates the state using some other hook. helix.hooks/use-subscription can cover this use-case in stable react versions today. here's a rough sketch:

(defhook use-observable
  [rx]
  (hooks/use-subscription
    (hooks/use-memo
     [rx]
     {:get-current-value #(deref rx)
      :subscribe (fn [callback]
                   (let [unsub (subscribe! rx callback)]
                      ;; function to call to unsubscribe when unmounting or `rx` changes
                      unsub))})))


(defnc some-component
  []
  (let [user-name (use-observable user-name-rx)]
    (d/div "Hello, " user-name)))

kennytilton 2021-07-12T19:12:43.180900Z

Awesome. I had my eyes on the error-boundary example, thought I saw the control I needed, but perhaps it would be less brittle to use hooks. I suspect performance will be excellent since they work so hard on that. Thx, @lilactown!