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:
parent
8166b9be3f
commit
3f30eb32c2
@ -17,8 +17,13 @@ trait ObservableImplicits {
|
|||||||
|
|
||||||
val prop = ObjectProperty[B](originalValue)
|
val prop = ObjectProperty[B](originalValue)
|
||||||
|
|
||||||
|
var prevValue = originalValue
|
||||||
def changeHandler = {
|
def changeHandler = {
|
||||||
prop.value = recalculate()
|
val newVal = recalculate()
|
||||||
|
if (prevValue != newVal) {
|
||||||
|
prop.value = recalculate()
|
||||||
|
prevValue = newVal
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a onChange changeHandler
|
a onChange changeHandler
|
||||||
|
Loading…
Reference in New Issue
Block a user