dart-archive / polymer-dart

Polymer support for Dart
https://pub.dartlang.org/packages/polymer
BSD 3-Clause "New" or "Revised" License
180 stars 33 forks source link

Is this a bug: ready() in a super class is not called #695

Closed jolleekin closed 8 years ago

jolleekin commented 8 years ago

The ready method in a super class is no longer called without an explicit overriding method on the child class.

// This base element has no HTML.
class BaseElement extends PolymerElement {
  BaseElement.created(): super.created();

  void ready() {
    print('BaseElement.ready called');
  }
}

@PolymerRegister('my-element')
class MyElement extends BaseElement {
  MyElement.created: super.created();

  // Without this line, [BaseElement.ready] will not be called.
  void ready() => super.ready();
}

I'm using polymer 1.0.0-rc.15.

jakemac53 commented 8 years ago

This is working as intended, extending anything other than PolymerElement is not supported. Instead, you should use a behavior.

For example in this case:

@behavior
abstract class ReadyBehavior {
  static ready(PolymerElement instance) {
    print('ReadyBehavior.ready called');
  }
}

@PolymerRegister('my-element')
class MyElement extends PolymerElement with ReadyBehavior {
  MyElement.created() : super.created();
}

The ready method on your class and all your behaviors will be invoked (this is why its a static method). There is no need to call super() when using behaviors.