Fix Observable.map to suppress nil changes

If the new output is equal to the old output, we'll suppress the change
message altogether, so as not to do unnecessary recalculations.

E.g., imagine you have a property `isOdd`. If you go from 27 to 319,
there's no need to trigger all the downstream objects to recalculate.
(Most of the other functional primitives I've created already have this
behavior.)
This commit is contained in:
Sarah Gerweck 2015-08-10 19:05:54 -07:00
parent 8166b9be3f
commit 3f30eb32c2

View File

@ -17,8 +17,13 @@ trait ObservableImplicits {
val prop = ObjectProperty[B](originalValue)
var prevValue = originalValue
def changeHandler = {
val newVal = recalculate()
if (prevValue != newVal) {
prop.value = recalculate()
prevValue = newVal
}
}
a onChange changeHandler