Fork me on GitHub
Quentin Le Guennec15:02:17

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


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:

❤️ 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)?


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


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?


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?


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?


(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


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?


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?


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


I think this is the section in the docs that talk about them

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 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 []}
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 {}.