Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObservableList not updated in template #21568

Closed
DartBot opened this issue Nov 11, 2014 · 4 comments
Closed

ObservableList not updated in template #21568

DartBot opened this issue Nov 11, 2014 · 4 comments
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams.

Comments

@DartBot
Copy link

DartBot commented Nov 11, 2014

This issue was originally filed by [email protected]


What steps will reproduce the problem?

  1. create a custom element with an ObservableList field (mylist)
  2. put the list in the element template ({{mylist}})
  3. add a new element to the list

What is the expected output? What do you see instead?
I should see the list updated (["new element"]), instead the list is not updated ("[]").

What version of the product are you using?
Dart 1.7.2, polymer-expression 0.13.0

Please provide any additional information below.

@DartBot
Copy link
Author

DartBot commented Nov 11, 2014

This comment was originally written by @zoechi


I encountered this very recently with a Map.
When you have a field

@observable
List myList = [];
// or even
// List myList = toObservable([]);

and add it to the template of your Polymer element like

{{myList}}

Id doesn't get updated when you add/remove/modify items in the List.
This is mostly because myList hasn't changed and this is what {{myList}} refers to.
myList still refers the same list.

{{myList}} implicitely uses toString() but it seems toString() is not observed for changes.
{{myList.toString()}} doesn't change this (at least this was the case for my Map example).

If you do something like

void addItem(Event e) {
  myList.add('xxx');
  var tmp = myList;
  myList = null;
  new Future(() => myList = tmp);
}

then the view is updated.

Using a filter didn't help either

String asString(List val) {
 return val.toString()
}

{{myList | asString}}

What should work is

String _oldMyListString;
@observable
String get myListString => myList.toString();

myList.changes.listen((recs) {
  _oldMyListString = notifyPropertyChange(#myListString, _oldMyListString, myListString);
});

{{myListString}}

caution: code not tested

Maybe someone from the Dart team knows a better workaround...

@kasperl
Copy link

kasperl commented Nov 12, 2014

Added Area-Pkg, Pkg-Observe, Triaged labels.

@jakemac53
Copy link
Contributor

This has caused a lot of confusion and come up a few times, I might spend a bit of time today seeing if I can get it working correctly. This is really only useful as a debugging feature but I think that even if its just for that its worth getting right.

@DartBot DartBot added Type-Defect area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. labels Nov 12, 2014
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

This issue has been moved to dart-archive/observe#72.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams.
Projects
None yet
Development

No branches or pull requests

4 participants