dart-archive / polymer-dart

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

Initial selection does not work in cor-list-dart #555

Closed rvaleev closed 8 years ago

rvaleev commented 9 years ago

So I have:

<core-list-dart id="list" data="{{data}}" selection="{{selection}}" fit>
    <template>  
                 <custom-element value="{{model}}" class="{{ {selected: selected} }}"></custom-element>
    </template>
</core-list-dart>

dart part:

@CustomTag('main-app')
class MainApp extends PolymerElement {
  @observable List data = toObservable([]);
  @observable var selection;

  @override
    domReady() {
      super.domReady();
      load();
   }

  Future loadChallenges() async {
     try {
       List result = //loading....
       data = toObservable(result);
     } catch (e, stackTrace) {
       .....
     }
  }

  @ObserveProperty('data')
  void setDefaultSelection() {
     selection = data.firstWhere(...); // peak one to be selected by default
  }

  @ObserveProperty('selection')
  onSelection() {
    log.info("selected: $selection");
  }

The outcome is not as expected: nothing is selected on application load I would expect that the one selected in setDefaultSelection will have selected class.

In logs I see two lines from onSelection:

2015-08-07 20:38:58.865: selected: ... here is proper toString of desired element
2015-08-07 20:38:58.934: selected: null 

It behaves like I've clicked twice on the same row, I assume that somewhere in the code it has false positive conclusion about selection.

core_elements: version: "0.7.1+2" polymer: version: "0.16.3+3"

jakemac53 commented 8 years ago

If this is still an issue please refile on the core-elements repo