Fork me on GitHub
#fulcro
<
2020-08-24
>
zhuxun207:08:29

I have been trying to implement the following and so far not able to find a way: I have a list of items displayed on the page. An item can be active or inactive depending on its current state. Every active item has a "progress" which needs to be displayed on it as a percentage (this value is stored and constantly being updated on the server). Now, I need to implement a probing mechanism for repeatedly retrieving the latest progress numbers for all the active items (with say 10 second intervals), and the probing should only happen when the there's at least one active item.

zhuxun207:08:10

The first question is: where should I put the timer code? Seems that I might want to put it at a hook that gets called every time the item states are changed. Is there such a hook?

zhuxun207:08:18

The reason I would want to have the timer logic in a state monitoring hook rather than in the client init function is that I would want to not probe when there's no active items (which is the majority of the time).

cjsauer13:08:10

There’s always the option of checking for active items in the actual timer firing event, and then avoiding the load! it there are none. Not sure how many items you’ll be working with tho. Fulcro does have react hooks support as well. Might be worth looking at. http://book.fulcrologic.com/#_react_hooks_support

👍 3
JAtkins13:08:05

1 possible way to do it: You could create a recursive mutation, using set-timeout from js to get the 10s delay. When no active users are remaining flip a switch in the db and the mutation kills itself. (i.e. does not schedule itself again)

👍 3
souenzzo19:08:36

@tony.kay where I assoc (assoc-in sui/all-controls [?report ?field :inst] (fn [app value] ...) ?? (to customize ALL field of type :inst in reports)

tony.kay20:08:23

@souenzzo report fields can have styles. See semantic ui plugin’s code (just look at that all-controls definition)

souenzzo20:08:51

ATM I'm using this ro/field-formatters {:app/date (fn [app value] (.toLocaleDateString value ...))}

souenzzo20:08:45

I will search about SUI plugins

zhuxun221:08:40

I found it interesting that the "state" in a UI State Machine is not really a complete snapshot of the local "model" (in an MVC sense.) Rather, it's almost just a helper for the UISM event routing to decide which handler gets called when such event is handled at multiple states. The meat of UISM seem to always be in the event handlers, in the form of side-effecting. I found UISMs in fulcro more like attachments closely snapped onto the UI code. They read values directly from the UI and generate side-effects directly on to the UI. The attachments themselves only have a loose (leaky) sense of "state", and writing them don't feel like writing a self-contained "model" or "state machine" at all as you probably need to know a lot about the specific UI itself.

zhuxun221:08:22

But I guess it aligns with the recurring theme in Fulcro that the model knowing the UI has some benefits (e.g. the model knowing the shape of the UI query avoids needing to sync the model code and the UI code; the model knowing the names of the UI props means one doesn't have to manually map them; etc)

tony.kay21:08:38

You are in a state, and yes, the rest of it is part of the intentional design

tony.kay21:08:05

it actually works out quite well…RAD has a grand total of 2 UIMS machines that can control any standard form (nested) or report independent of UI

tony.kay21:08:10

the point is to concentrate logic and add a little bit of FSM to it…there is a state that is tracked, which you are in, which determines where you are in (your) state diagram, and also then defines the edges (triggered by events)

tony.kay21:08:30

but it is by no means an academic state machine system…it just borrows most of the practically useful stuff for this particular abstraction

tony.kay21:08:26

That is also why it isn’t called FSM, or state charts…they are UI state machines…with full-stack in mind

tony.kay21:08:01

Fulcro is pragmatic 1st, by design

zhuxun222:08:50

I see. It makes much more sense now. No I'm not criticizing fulcro, just an effort to orient myself and develop an intuition for your design

tony.kay22:08:33

yep, I didn’t take it as criticism 😄

tony.kay22:08:21

To be honest certain namespaces, such as dynamic-routing and ui-state-machines, started out as pure experiments to see how the design of them would work. They were both in F2 incubator. I found them to be quite useful myself and promoted them to the library proper. That said, they are somewhat radical in their design in that they leverage things only Fulcro has (at least that was the case when written…some things may have since appeared in other places in other libs, or may have predated my “invention”).

tony.kay22:08:31

well, for that matter, I guess most of the entire library is a series of experiments that have “mostly” gone right 😜