Skip to content

make it easier to extend / mixin Property & EventStream #40

@Andersmholmgren

Description

@Andersmholmgren

I want to find a really clean way to integrate frappe with polymer. I want a class that is

  • a true frappe Property / EventStream
  • directly usable in as a property in polymer expressions

So far I've sketched out the following

class ObservableProperty<T> extends PropertyProxy<T> with ChangeNotifier {
  StreamSubscription _subscription;
  T _oldValue;
  final Symbol _propertyName;

  ObservableProperty(Property<T> property, this._propertyName) : super(property);

  @override
  void observed() {
    if (_subscription == null) {
      _subscription = listen((T v) {
        final old = _oldValue;
        _oldValue = v;
        notifyPropertyChange(_propertyName, old, v);
      });
    }
  }

  @override
  void unobserved() {
    if (_subscription != null) {
      _subscription.cancel();
    }
  }
}

Unfortunately PropertyProxy is like

class PropertyProxy<T> implements Property<T> {
  final Property _property;
  PropertyProxy(this._property);

  @override
  Property operator *(Property other) => _property * other;

 ... 74 other methods like this :-(

That is because there is no easy way to extend Property or mix it in. Firstly all the constructors are factories (which I think is just a left over from previous versions of Frappe) but also the methods directly invoke property constructors like

new Property.fromStream(

so will not return any derived class. Totally understandable but a pain when trying to extend.

Please add some support for making this easier.

Of course I wouldn't be upset if you directly supported the observe package so I didn't need to build the extension ;-)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions