Fork me on GitHub
#fulcro
<
2022-02-22
>
Quentin Le Guennec15:02:17

Can I run transact! without a component? e.g. in the then callback of a promise

1
dvingo15:02:06

ya - you can pass a fulcro app - and if you want you can set the :ref option on the transaction, this is what transact! does when you pass a component instance: https://github.com/fulcrologic/fulcro/blob/a5f5b2121ca97739bf986412bf3c081c3a078b33/src/main/com/fulcrologic/fulcro/raw/components.cljc#L409

❤️ 1
Quentin Le Guennec19:02:29

perfect thank you!

Quentin Le Guennec19:02:44

Hi, how can I update ui according to a statemachine state? (something like :query for statemachines)?

1
sheluchin19:02:05

This is a very general question. The main thing to remember is that the UI is a function of the Fulcro client DB (`view = fn(data)`). The short answer is that you update your UI by updating the database using mutations (`transact!`) and loads (`merge!`, load!).

Quentin Le Guennec19:02:50

thank you, I actually found my answer here, I was looking for uism/asm-ident

sheluchin19:02:07

Ah, I guess I misunderstood a little. Good luck 🙂

Quentin Le Guennec20:02:49

Is there a way to access component props in the :query attribute?

sheluchin20:02:51

Why would you want to do that?

Quentin Le Guennec20:02:01

Because I need to retrieve the uism/asm-ident corresponding to that component ident.

Quentin Le Guennec20:02:30

{:query         (fn [] [:connect/id :connect/name
                         (uism/asm-ident [:connect/id id])])}

Quentin Le Guennec20:02:33

but I guess this is circular reasoning, right?

sheluchin20:02:15

I think you should be identifying your asm by keyword there. The ASM id won't be the same as the current component id, I don't think..

Quentin Le Guennec20:02:54

It is, I initialize it with:

(uism/begin! this providers/connect
                                        [:connect/id id]
                                        {:actor/connect-button this})

Quentin Le Guennec20:02:09

the id is [:connect/id id]

Quentin Le Guennec20:02:04

Am I not allowed to do that? If not, how do I make parametrized state machines?

sheluchin20:02:35

(uism/begin! app-or-component machine-def instance-id actor-map)

    Installs an instance of a state machine (to be known as instance-id, an arbitrary keyword), based on the definition in machine-def, into Fulcro’s state and sends the ::uism/started event.

Quentin Le Guennec20:02:54

oh yeah, a keyword

Quentin Le Guennec21:02:01

that's very limiting, though

sheluchin21:02:09

I think what you want is to add an actor to that state machine and have that actor correspond to your component, rather than coupling your SM to your UI at the top level.

❤️ 1
Quentin Le Guennec21:02:50

Yes, but I have multiple instances of the same component that each need to access their own SM instance

Quentin Le Guennec21:02:03

should I open a feature request?

sheluchin21:02:37

I think you should try to describe what you're trying to do in a bit more detail and see if someone with a bit more experience can help you out.

Jakub Holý (HolyJak)12:02:16

You can have multiple instances of a component, each with its own instance of the SM, the component instance being an actor in the uism.

Quentin Le Guennec23:02:48

There's something I'm missing from the fulcro picture. How does a component query data outside of its local :initial-state?

donavan09:02:27

It may be better to explain more of what you’re trying to achieve but you could possibly use ident joins. I’m not sure if there is a section in the docs for it but if you search for ident join Some info on link queries which are a kind of special case ident join https://book.fulcrologic.com/#_link_queries

donavan09:02:51

I think this is the section in the docs that talk about them https://book.fulcrologic.com/#_idents_as_a_query_element

Quentin Le Guennec09:02:38

Thank you, I'll look for that

Jakub Holý (HolyJak)12:02:44

BTW initial state is only one source of data. Merge or df/load is another. To access data not belonging to the data entity, use Ident or Link queries - see https://blog.jakubholy.net/2020/fulcro-divergent-ui-data/ But make sure you understand Fulcro well and are not trying to force an incorrect solution to a need. As suggested elsewhere, the minimalist tutorial and its exercises should help.

Björn Ebbinghaus15:02:56

@U0111PVCS8P What I think is important for you to understand is, that the queries of components are not run against a database on their own. It is not like your components query for data and get "their own data" delivered straight from the database. Instead, queries are composed together and in the end there is only one query run against one (normalized) database. This query is located in your "Root Component". In the end, your root component gets a single tree of data, that it feeds down your render functions.

Björn Ebbinghaus16:02:30

This, for example, doesn't work:

(def db 
  {:foo "bar"})

(defsc B [{:keys [foo]} _]
 {:query [:foo]}
 (dom/p "foo"))

(def ui-b (comp/factory B))

(defsc Root [_ _]
 {:query []}
 (ui-b))
B doesn't "pull" :foo from the db by itself. The query of the root component is used to shape the normalized database into a denormalized tree. This tree is fed to the render function of the root component. And because the query of the root node is [], the data fed to the root is empty {}.