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
Hello, I'm quite new to programming (but not new to attempt to programming), and just started migrating from JavaFX. i'm new to Kotlin and don't know if is a issue, it's about the code example below:
classPersonModel : ItemViewModel<Person>() {
valfirstname = bind(Person::firstName)
vallastName = bind(Person::lastName)
overridevalonCommit(commits: List<Commit>) {
// The println will only be called if findChanged is not null commits.findChanged(firstName)?.let { println("First-Name changed from ${it.first} to ${it.second}")}
commits.findChanged(lastName)?.let { println("Last-Name changed from ${it.first} to ${it.second}")}
}
privatefun <T> List<Commit>.findChanged(ref: Property<T>): Pair<T, T>? {
valcommit = find { it.property == ref && it.changed}
returncommit?.let { (it.newValueasT) to (it.oldValueasT) }
}
}
if i'm right, the logic say's that it.first value references from it.newValue (the first value of the Pair<T, T>), and it.second from the second value, stored as it.oldValue. So, i think the print message should say that the commit value changed from a old value to a new value, but in my case the message prints the other way wound (from old to new):
text changed from 1 to
text changed from 12 to 1
text changed from 123 to 12
text changed from 1234 to 123
text changed from 12345 to 1234
text changed from 123456 to 12345
should not the .findChanged function store the it.oldValue in the first pair's argument, or the println message reference from the it.second and then it.first?
if i'm not doing something very wrong, here are my suggestion:
classPersonModel : ItemViewModel<Person>() {
valfirstname = bind(Person::firstName)
vallastName = bind(Person::lastName)
overridevalonCommit(commits: List<Commit>) {
// The println will only be called if findChanged is not null commits.findChanged(firstName)?.let { println("First-Name changed from ${it.first} to ${it.second}")}
commits.findChanged(lastName)?.let { println("Last-Name changed from ${it.first} to ${it.second}")}
}
privatefun <T> List<Commit>.findChanged(ref: Property<T>): Pair<T, T>? {
valcommit = find { it.property == ref && it.changed}
returncommit?.let { (it.oldValueasT) to (it.newValueasT) }
}
}
or:
classPersonModel : ItemViewModel<Person>() {
valfirstname = bind(Person::firstName)
vallastName = bind(Person::lastName)
overridevalonCommit(commits: List<Commit>) {
// The println will only be called if findChanged is not null commits.findChanged(firstName)?.let { println("First-Name changed from ${it.second} to ${it.first}")}
commits.findChanged(lastName)?.let { println("Last-Name changed from ${it.second} to ${it.first}")}
}
privatefun <T> List<Commit>.findChanged(ref: Property<T>): Pair<T, T>? {
valcommit = find { it.property == ref && it.changed}
returncommit?.let { (it.newValueasT) to (it.oldValueasT) }
}
}
in my case i got it right:
text changed from to 1
text changed from 1 to 12
text changed from 12 to 123
text changed from 123 to 1234
text changed from 1234 to 12345
text changed from 12345 to 123456
The text was updated successfully, but these errors were encountered:
Hello, I'm quite new to programming (but not new to attempt to programming), and just started migrating from JavaFX. i'm new to Kotlin and don't know if is a issue, it's about the code example below:
if i'm right, the logic say's that
it.first
value references fromit.newValue
(the first value of thePair<T, T>
), andit.second
from the second value, stored asit.oldValue
. So, i think the print message should say that the commit value changed from a old value to a new value, but in my case the message prints the other way wound (from old to new):should not the
.findChanged
function store theit.oldValue
in the first pair's argument, or the println message reference from theit.second
and thenit.first
?if i'm not doing something very wrong, here are my suggestion:
or:
in my case i got it right:
The text was updated successfully, but these errors were encountered: