Skip to content
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

Properties aren't delivering the current value to multiple listeners #25

Closed
Andersmholmgren opened this issue Dec 23, 2014 · 1 comment

Comments

@Andersmholmgren
Copy link

The following prints

p1: first
p2: true
p1b: first

but should print

p1: first
p2: true
p1b: first
p2b: true
main() async {
  listen(Reactable r, String l) =>
      r.listen((v) => print('$l: $v'));

  final p1 = new Property.constant('first');
  final p2 = p1.map((s) => s == 'first').asProperty();

  listen(p1, 'p1');
  listen(p2, 'p2');

  await new Future.delayed(const Duration(milliseconds:100));

  listen(p1, 'p1b');
  listen(p2, 'p2b');

  await new Future.delayed(const Duration(milliseconds:100));
}

It seems that as map turns the property into a stream, the call to asProperty comes too late to save the value???

Incidentally it would be really nice if Property implemented map and returned a Property rather than needing to call asProperty(). Or maybe what is needed is another method with these semantics.

I find it is super common to derive properties from properties. In fact you could increasingly describe my whole app that way ;-)

@danschultz
Copy link
Owner

Looks like the current value is not actually being delivered to multiple listeners. This only happens when you add a delay, because the listener is added in another event loop.

The test case can be simplified with this:

var p = new Property.constant(1).map((s) => s + 1);
p.listen(print);

new Future.delayed(new Duration(milliseconds: 100), () {
  p.listen(print);
});

I'll rename the ticket.

@danschultz danschultz changed the title mapped properties don't have an initial value Properties aren't delivering the current value to multiple listeners Dec 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants