so .. we want to use tornadofx as a viewer for a n...
# tornadofx
n
so .. we want to use tornadofx as a viewer for a non fx based core, what is the best way to make lists observable? atm i have mostly MutableList and MutableMaps, exposed as List and Maps mostly is there a way for tornadofx to register a callback that the core can call on change that triggers a update for the observable properties or would it be a better idea to use coroutines in the core and send updated values via channlels? can tfx listen to those and convert them into observables ?
s
Not sure if I'm understanding the issue correctly, but for "what is the best way to make lists observable" can you not just use an ObservableList? https://docs.oracle.com/javase/8/javafx/api/javafx/collections/ObservableList.html
They have an ObservableMap as well
TornadoFX has a wrapper that is
obseravbleListOf()
that will return a FXCollections ObserableList
then I can call
myObservableList.onChange { do stuff }
n
yes i can but my core code would be best to not depend on javafx, because its not available on openjdk without openfx
unless ofc i shadow it in which will break other things..
so waht i am doing now is making fake observable sollections.. that trigger callbacks, which i can catch on the tfx side and update a actual observablelist
s
That's the only way I can think to do it, even though it's messy. 😞 I haven't messed around with coroutines within TornadoFX yet so I can't really offer any suggestions. Sorry!
n
i could do it another way.. use vars and replace MutableLists with ObservableLists the core could would nto even notice the swap
but it would make the code really ugly
is there any methods on ObservableLists that can replace all contents in one operation? not clear and add all