fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
lgessler 2020-12-28T01:28:01.356500Z

:initLocalState is tied to the react component's lifecycle, isn't it? so it should get called every time your component is mounted, which could happen more than once for a single page render but might not necessarily

tony.kay 2020-12-28T02:12:14.356700Z

Pure react. It's part of the generated constructor

tony.kay 2020-12-28T02:12:36.356900Z

So mount/unmount

Mr. Savy 2020-12-28T03:31:39.362400Z

@tony you suggested the possibility of a scroll trigger a while ago. from what I'm seeing, it looks like I'd need to create a usim/trigger event of some kind for this. Is that right, or are there other available approaches? I guess maybe I could attach it to a div. would that be :onScroll ?

Jakub Holý 2020-12-28T08:49:50.363900Z

Well, you knew the problem was that your query did not return the data you expected.... 🙂

Helins 2020-12-28T11:42:03.364400Z

@holyjak Hot reloading by shadow-cljs Yes but :initLocalState does not seem to be updated even for newly mounted components (after the hot reload), and that is the part I find weird. Since they are newly mounted, they should call the newly reloaded ctor code, shouldn't they?

Jakub Holý 2020-12-28T12:16:29.364600Z

Are you 100% sure that hot reload did remount them? Perhaps add the on Component Mounted hook and log from there?

ej 2020-12-28T13:24:25.366200Z

Is defsc short for define stateful component?

2👍
wilkerlucio 2020-12-29T11:44:46.379Z

I personally use a lot of defsc to define UI root components, they usually dont have any query but I want defsc to use the fulcro css system

tony.kay 2020-12-29T15:42:35.384Z

@wilkerlucio do you even mount those, or just use them for a place to put namespaced CSS?

wilkerlucio 2020-12-29T15:43:30.384400Z

yes, I mount them, they are usually the design system part of the application, buttons, checkboxes...

wilkerlucio 2020-12-29T15:50:44.384600Z

example case in Fulcro inspect code: https://github.com/fulcrologic/fulcro-inspect/blob/master/src/ui/fulcro/inspect/ui/core.cljs

tony.kay 2020-12-29T16:06:32.385300Z

oh, you don’t mean “root” components. I think you mean “stateless leaf” components 😉

tony.kay 2020-12-29T16:07:01.385500Z

root to me means something you pass to mount

wilkerlucio 2020-12-29T16:49:57.386400Z

sorry, bad naming on my part

wilkerlucio 2020-12-29T16:50:03.386600Z

yeah, not root

wilkerlucio 2020-12-28T13:42:36.366400Z

which is unfortunate, given you can also use it for stateless components, but will not change for compatibility

Björn Ebbinghaus 2020-12-28T13:42:40.366600Z

> The name means “define stateful component” and is intended to be used with components that have queries (though that is not a requirement). https://book.fulcrologic.com/#_the_defsc_macro

Helins 2020-12-28T14:25:33.366800Z

I am 100% sure that :initLocalState is never updated once it has been set once. That is, after modifying :initLocalState, even new components (which are mounted only after hot reload) do not execute the new code. I have to refresh the page myself.

JAtkins 2020-12-28T16:13:02.367Z

@ajsnow2012 I'm (slowly) grabbing them and putting them on this doc. https://roamresearch.com#/app/CommunityFulcro/page/12-26-2020

1👍
tony.kay 2020-12-28T18:10:24.367800Z

well, then that would be a bug @adam678. Perhaps a regression? I’ve used that feature and do not remember such misbehavior, but perhaps I was using it in a circumstance where it didn’t matter

JAtkins 2020-12-28T19:54:07.369500Z

React HOC components in theory work fine with fulcro I think. (defsc wrapping defsc). Is there any reason to not write code this way, and if so what is the alternative that still allows me to decorate components with additional functionality?

JAtkins 2020-12-28T19:54:56.369600Z

Perhaps use defsc* to generate components dynamically that merge the queries and initial state of the wrapped and wrapper classes?

Jakub Holý 2020-12-28T20:12:23.369900Z

I haven't so far had a need for a HoC but I've only built two applications...

JAtkins 2020-12-28T20:15:19.370100Z

I'm trying to make a generalized "highlight on hover and tell X that you are hovered" pattern... Maybe it's just a fn wrapper? I know there are several ways to hack it together, just not sure of the best way to hack it together 🙂

JAtkins 2020-12-28T20:17:39.370300Z

Pure stateless fn wrapper

(fn wrap-highlight [factory* notify-fn*]
  (fn wrap-highlight* [props]
    (dom/div {:onMouseOver #(notify-fn* ...)}
      (factory* props))))

JAtkins 2020-12-28T20:18:02.370600Z

But that feels wrong

JAtkins 2020-12-28T20:27:09.371400Z

Related question: is it sane to have another component render your children?

(defsc WrapperWhatever [this {:keys [:component/id] :as props} {:keys [child-props child-factory]}]
  {:query [:component/id :component/local-state]
   :ident :component/id}
  (dom/div #_"whatever mess you want in your wrapper"
    (child-factory child-props)))

(def ui-wrapper-whatever (comp/computed-factory WrapperWhatever {:keyfn :component/id}))


(defsc ParentThing [this {:keys [:parent/id :parent/child :parent/sub-wrapper] :as props}]
  {:query [:parent/id
           {:parent/child (comp/get-query SomeComponent)}
           {:parent/sub-wrapper (comp/get-query WrapperWhatever)}]
   :initial-state {:parent/child {}
                   :parent/sub-wrapper {}}
   :ident :parent/id}
  (dom/div
    (ui-wrapper-whatever sub-wrapper {:child-props child :child-factory ui-some-component})))

(def ui-parent-thing (comp/factory ParentThing {:keyfn :parent/id}))

JAtkins 2020-12-28T20:29:28.371500Z

I guess this is almost the exact same question actually. Just a different approach (dare I say a more sane one?)

Jakub Holý 2020-12-28T20:34:41.371700Z

No time to read the code now but I believe there are examples of this in the book, perhaps using pure JS HoC

JAtkins 2020-12-28T20:35:54.371900Z

Yeah, this is about as close as I think I can come to mirroring the regular JS HOC pattern

2020-12-28T20:50:25.372100Z

wrapping defsc is a good idea, Wilker talks about it here: https://www.youtube.com/watch?v=R_XPwi0Kiwk

1👀1❤️