danschultz / frappe

A Dart package for functional reactive programming

Home Page:http://pub.dartlang.org/packages/frappe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reactable.collect requires all properties to update to produce a new event

Andersmholmgren opened this issue · comments

If you uncomment the cProperty2.value = 'secondb'; line it will work

main() async {
  ControllableProperty<String> cProperty1;
  ControllableProperty<String> cProperty2;
  ControllableProperty<String> cProperty3;
  List<Property<String>> listOfProperty;
  Property<List<String>> propertyList;
  List<List<String>> receivedEvents;

  cProperty1 = new ControllableProperty('first');
  cProperty2 = new ControllableProperty();
  cProperty3 = new ControllableProperty();

  listOfProperty = [ cProperty1.property, cProperty2.property,
    cProperty3.property ];

  propertyList = Reactable.collect(listOfProperty);

  receivedEvents = [];
  propertyList.listen((e) => receivedEvents.add(e));
  cProperty1.property.listen((v) => print('p1: $v'));
  cProperty2.property.listen((v) => print('p2: $v'));
  cProperty3.property.listen((v) => print('p3: $v'));
  propertyList.listen((v) => print('plist: $v'));
  await new Future.delayed(const Duration(milliseconds:100));
  cProperty1.value = 'first';
  cProperty2.value = 'second';
  cProperty3.value = 'third';

  await new Future.delayed(const Duration(milliseconds:100));
  cProperty1.value = 'firstb';
//  cProperty2.value = 'secondb';
  cProperty3.value = 'thirdb';
  await new Future.delayed(const Duration(milliseconds:100));
}

Helper classes used in above

class ControllableEventStream<T> {
  final StreamController<T> controller;
  EventStream<T> _eventStream;
  EventStream<T> get eventStream => _eventStream;

  ControllableEventStream._internal(this.controller) {
    _eventStream = new EventStream(controller.stream);
  }

  ControllableEventStream.std()
      : this._internal(new StreamController.broadcast());

}

class ControllableProperty<T> {
  final ControllableEventStream<T> _controllable;
  final Property<T> property;

  void set value(T v) {
    _controllable.controller.add(v);
  }

  ControllableProperty._(T initialValue, ControllableEventStream<T> controllable)
      : this._controllable = controllable,
        this.property = initialValue != null ?
            new Property.fromStreamWithInitialValue(initialValue,
                controllable.eventStream) :
              new Property.fromStream(controllable.eventStream);

  ControllableProperty([T initialValue])
      : this._(initialValue, new ControllableEventStream.std());
}

Fix for #25 may have fixed this.

Confirmed that #25 fixes this. Thanks for the all the bug reports!