-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SimpleVar notifies Observers with wrong value #59
Comments
Yes, please, try to come up with a test case. |
Probably the piece you are missing is that ValBase<T> extends ObservableBase<Consumer<? super T>, T> A canonical description of the change is the old value (the second type argument to Then both |
Morning, I cannot commit from work, but I can at least paste something in here. For me, the following test case fails on 2.0-M5. public class VarTest
{
@Test
public void checkSimpleVar()
{
final String firstVal = "foo";
final String secondVal = "bar";
final Var<String> var = Var.newSimpleVar(firstVal);
// Check that only invalidation is fired when setting the same value again.
final Subscription sub1 = Subscription.multi(
var.observe(it -> fail("Observer was notified without change.")),
var.observeInvalidations(it -> assertEquals("Invalidation Observer was notified with wrong Observable.", var, it)),
var.observeChanges((obs, oldVal, newVal) -> fail("Change Observer was notified without change.")));
var.setValue(firstVal);
sub1.unsubscribe();
// check that everyone receives the right values on a real change
final Subscription sub2 = Subscription.multi(
var.observe(it -> assertEquals("Observer was notified with wrong value.", secondVal, it)),
var.observeInvalidations(it -> assertEquals("Invalidation Observer was notified with wrong Observable.", var, it)),
var.observeChanges((obs, oldVal, newVal) ->
{
assertEquals("Change Observer was notified with wrong Observable.", var, obs);
assertEquals("Change Observer was notified with wrong old value.", firstVal, oldVal);
assertEquals("Change Observer was notified with wrong new value.", secondVal, newVal);
}));
var.setValue(secondVal);
sub2.unsubscribe();
}
} And it fails pretty hard. The Observer (from Interestingly, the later method works the first time, when no actual change occured. I have no idea yet how exactly this happens. |
Excuse my brevity, it is very late night where I am, but everything seems to work as it should. The observer registered with |
Oh, interesting, I read that as an implementation detail, sorry. So, what's the point then to have Well, you go to sleep, I will think of an idea to make the API a little clearer. ;) |
OK, my thoughts so far. First of, I've found the documentation on I see the point to have one class or interface that does the observer management. But the two most prominent examples for It might be beneficial to use two different interfaces to describe streams and observable values (in this case meaning just the concept, not any implementation). That is where the main "rift" is, between stateful and stateless. Different types of observable values can probably agree on some common type of listener, and so can different streams. That would mean some code duplication, but currently I think it might be worth it. Of course, there is the As for the rest, having Wow, this sounds more like a rant than I meant to, sorry for that. I like working with ReactFX, so I get a bit passionate. In short, I think the best version for Because Don't get me wrong, I'm not actually suggesting to do all this. But at the very least, I hope it gives a few hints to writing the documentation. |
The methods on
Apart from the I think I would accept a pull request changing the argument of |
There is a common denominator—notification about an event. That in some cases the notification describes a state change, doesn't matter.
Even if they don't agree on the type of listener, the listener management turns out to be the same (though it took some effort to get there, to have a common base for all of I think the only problem is the inability to hide the |
It seems I've found a nasty bug in 2.0-M5. When
setValue(newVal)
is called onSimpleVar
, it updates the fieldvalue
onSimpleVar
, then callsinvalidate()
from its super classValBase
. This in turn notifies allObservers
using its own fieldvalue
. But the later only gets updated ongetValue()
, which was never called.Maybe I'm missing something here. I don't get that
AccuMap
thing (yet). I'll try to come up with a test case later.The text was updated successfully, but these errors were encountered: