carlw
09/25/2018, 8:52 PMcarlw
09/25/2018, 8:52 PMcarlw
09/25/2018, 8:54 PMcarlw
09/25/2018, 8:57 PMValV
09/25/2018, 9:08 PMarxenix
09/25/2018, 9:08 PMinit{}
block of my main view, I have this:
runAsync {
filters = tracker.fetchFilters()
println("done fetching filters! ${filters.size}")
fire(SearchFiltersEvent(filters))
sort = tracker.fetchSorts()
println("done fetching sort!")
fire(RequestItemsEvent)
}
SearchFiltersEvent is marked as RunOn.ApplicationThread, and RequestItemsEvent is marked as RunOn.BackgroundThread
For some reason, the subscriber for SearchFiltersEvent gets the event, but the subscriber for RequestItemsEvent doesn't.arxenix
09/25/2018, 9:09 PMValV
09/25/2018, 9:14 PMobject RequestItemsEvent : FXEvent(BackgroundThread)
?arxenix
09/25/2018, 9:16 PMclass SearchFiltersEvent(val searchFilters: List<SearchFilter>): FXEvent()
object RequestItemsEvent: FXEvent(EventBus.RunOn.BackgroundThread)
arxenix
09/25/2018, 9:16 PMarxenix
09/25/2018, 9:17 PMfire(RequestItemsEvent)
with a delay, it works properlyarxenix
09/25/2018, 9:17 PMTimer().schedule( timerTask {
fire(RequestItemsEvent)
}, 2000L)
ValV
09/25/2018, 9:19 PMValV
09/25/2018, 9:19 PMarxenix
09/25/2018, 9:21 PMarxenix
09/25/2018, 9:21 PMValV
09/25/2018, 9:22 PMarxenix
09/25/2018, 9:22 PMValV
09/25/2018, 9:27 PMedvin
09/25/2018, 9:41 PMedvin
09/25/2018, 9:45 PMinit
block of your main view, there is a distinct possibility that your event will fire before the rest of your UI is set up. You could probably just wrap the emission in a runLater
- this will cause it to be queued on the UI thread, but you wouldn't have a guarantee in this case either. I'd move that code to a controller, but also initialize it from onDock
since other UI elements are supposed to get notified of the event.arxenix
09/25/2018, 10:33 PMobject ComputeRequest: FXEvent(EventBus.RunOn.BackgroundThread)
fun heavyComputation() {
println("not really")
}
class MainView : View("Hello TornadoFX") {
init {
subscribe<ComputeRequest> {
heavyComputation()
}
fire(ComputeRequest)
}
override val root = hbox {
label("Hello World")
}
}
arxenix
09/25/2018, 10:33 PMheavyComputation()
never gets calledarxenix
09/25/2018, 10:35 PMarxenix
09/25/2018, 10:37 PMsubscribe
and fire
to an onDock() instead of init block, it works perfectly, but I don't really get whyValV
09/25/2018, 10:44 PMfire(...)
inside just init { ... }
will not reach the target. You should do init { runLater { fire(...) } }
. 'Cause runLater
will be executed after View is built up and readyValV
09/25/2018, 10:47 PMonDock()
is executed after a View is readyarxenix
09/25/2018, 10:56 PMarxenix
09/25/2018, 11:01 PMval card = find<ResultCardFragment>(mapOf(ResultCardFragment::item to item))
this@gridpane += card.apply {
gridpaneConstraints {
columnRowIndex(idx % 5, idx / 5)
columnSpan = 1
rowSpan = 1
}
}
Something simple like this works as expected:
this@gridpane += text(item.title) {
gridpaneConstraints {
columnRowIndex(idx % 5, idx / 5)
columnSpan = 1
rowSpan = 1
}
}
arxenix
09/25/2018, 11:03 PMcard.root.apply