https://kotlinlang.org logo
#tornadofx
Title
# tornadofx
t

Tim McCormack

01/15/2023, 9:05 PM
How am I supposed to manage global state across views in a tornadofx application?
I currently have a JavaFX application that has a single global
State
object that holds a lock on the application's data directory. It manages DB migrations and provides for various accessors and mutators on different data stores. So far so good.
I'm also using tornadofx's typed builders for some parts of the UI. This has been nice enough, but it would be nice to move the whole thing into tornadofx. However, the App needs to take an initial View, and the View needs to be able to be access the data via that global State instance. How is the View supposed to get access to it? Does the App hold onto it, and maybe the View can ask for it? Do I need to use a global singleton? Does it need to somehow be divided into Models and use inject() somehow?
w

wakingrufus

01/17/2023, 3:15 PM
if you global state is a model, you can just inject() it into any view
t

Tim McCormack

01/17/2023, 10:57 PM
I think the difficulty I'm having is that the global state isn't valid to use until some initialization has occurred, which might involve a different View.
Maybe I shouldn't bother with tornado's injection and models for this and I should actually just have a true singleton that can be fetched from anywhere by a
State.getSingleton()
call.
11 Views