Get help from the marimo community

Updated last week

Handling race conditions

What's the best way to handle race conditions? For instance, if I have a component A that B depends on, but C depends on A and a state that is set in B. How can I ensure that B is updated before C is updated, since the state update seems to hide reactivity
A
j
5 comments
The best thing to do is to minimize state usage 🙂 Recently refactored a user's notebook to remove all on_change handlers and instances of mo.state() — instead, we updated the code to pass UI elements values through the dataflow graph (built-in reactivity) and constructed new objects from existing ones, instead of mutating existing ones.

In this case, instead of setting a state in B, can you compute a new value, and have C depend on that new value as well as A?
(Barring removing mutations, you'd need to manually insert dependencies across cells, but this can be error prone and difficult to maintain)
Thanks! That's what I thought as well. So I've refactored to work with mo.ui.dictionary, and I realized I would love to be able to use nested dictionaries for this though, because I want to pass some metadata about the components as well
mo.ui.dictionary should be able to hold other mo.ui.dictionary objects, if that’s what you mean?
not exactly, they may hold other marimo objects, yes, and I didn't know that so thanks for pointing that out 🙂 but metadata could include stuff like "id", "tooltip" strings etc, that may be passed to factory methods, i.e. things that aren't marimo objects
Add a reply
Sign up and join the conversation on Discord