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

Bool attribute binding is still very very flakey #553

Closed DanielJoyce closed 8 years ago

DanielJoyce commented 9 years ago
<core-pages>
  <derp></derp>
  <derp></derp>
</core-pages>

dep is a custom element

When core-pages selects one of its children to be active, it sets a 'active' boolean attribute on it

<!-- what you see in the developer tools -->
<core-pages>
  <derp active></derp>
  <derp></derp>
</core-pages

class Derp extends PolymerElement{

   @PublishedProperty(reflect:true)
  bool get active{
   var a = readValue(#active);
   return a;
  }
  set active(bool newValue){
    print("ACTIVE: ${active}");
    writeValue(#active, newValue);
  }  

  @ObserveProperty("active")
  void observeActive(oldValue, newValue){
    window.console.log("ACTIVE ${oldValue} => ${newValue}");
  }

  void attached(){
       new PathObserver(this,"active").open((e) => window.console.log("PATH OBSERVE ACTIVE ${active} "));
  }
}

The html implementation of derp can be trivial and is not given here.

With or without the @PublishedProperty, these methods only ever fire ONCE when the active attribute is added to by core pages. When core-pages sets the other derp as active, removal of 'active' ( which should set derp.active = false ) is never detected, nor are subsequent re-additions of 'active' by core-pages.

I've tried all sorts of way to grab it, but nothing seems to work.

It seems the removal of the active attribute somehow kills the polymer-dart bindings so if a derp child of core-pages is ever marked active again (via core-pages.selected=0) , derp never sees the change.

Also removal does not cause 'active' property of derp to be set to false.

DanielJoyce commented 9 years ago

if I add this, I only ever see the following once, the first time core-pages makes derp active. Every subsequent time nothing is emitted as the binding looks be broken somewhere when active is removed.

changes.listen((e)=> window.console.log("CHANGE: ${e}"));

CHANGE: [#<PropertyChangeRecord Symbol("active") from: null to: true>]