You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the code below, why does xnow change along with x? e.g. I was expecting to see the "Observer N received click" to retain the N value that was assigned to xnow when the closure was initially created...
Observer 2 subscribing!
Observer 1 received click
Observer 2 received click
Observer 3 subscribing!
Observer 1 received click
Observer 3 received click
Observer 3 received click
Observer 4 subscribing!
Observer 1 received click
Observer 4 received click
Observer 4 received click
Observer 4 received click
import tornadofx.*
import io.reactivex.rxkotlin.*
import io.reactivex.Observable
import javafx.scene.control.*
class MyApp: App(MyView::class)
class MyView: View() {
override val root = vbox {
var clicks = button("Pressme").actionEvents()
var x = 1
clicks.subscribe { println("Observer 1 received click") }
button("Subscribe New Observer") {
setOnAction {
x++
println("Observer $x subscribing!")
clicks.subscribe { val xnow=x; println("Observer $xnow received click")}
}
}
}
}
The text was updated successfully, but these errors were encountered:
For the code below, why does xnow change along with x? e.g. I was expecting to see the "Observer N received click" to retain the N value that was assigned to xnow when the closure was initially created...
The text was updated successfully, but these errors were encountered: