[JavaFX] Bind bug? Or am I just stupid?
- April 14th, 2010
- Posted in JavaFX
- Write comment
I really love that binding stuff in JavaFX. I am looking forward until some smart guy implements something similar in Scala…
But I also have some problems with it. Sometimes “on replace” triggers are called with the same values for <old> and <new>. Here is a small sample script that shows it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import java.lang.RuntimeException; /** * @author johannes */ println( "Starting binding test..." ); var i = 0.5 on replace old { println( "i changed to <{i}>" ); if ( i == old ) { throw new RuntimeException( "This will never happen!" ); } }; var b = bind calc( i ) on replace old { println( "b has changed from <{old}> to <{b}>" ); if ( b == old ) { println( "!!!!!!!!!!!!!!!!!!!!!!!" ); println( "Why is on replace called? Both objects are the same: {isSameObject( b, old )}" ); println( "!!!!!!!!!!!!!!!!!!!!!!!" ); } }; println( "i: {i}" ); i = 0.5; println( "i: {i}" ); i = 0.9; println( "i: {i}" ); i = 1.0; println( "i: {i}" ); function calc( i ) { return i < 1; } |
Of course I have posted a question in the JavaFX forum. But no answers yet….
UPDATE:
Has finally been fixed in 1.3! Now it works as expected.
The “on replace” trigger will fire as long as you have performed an assignment operation. It will fire regardless whether the assignment was the same value or not.
@Richard: I am really looking forward to the 1.3 release….