Not an ID
Not an ID

Reputation: 2589

Polymer Dart: is @observable's new value inserted into DOM?

Say I have a custom element, who has a @observable Map model = toObservable({'k': 'v'}); in its dart file, and <span>{{model['k']}}</span> in its html file, when I changed model, how can I know, without using MutationObserver to observe DOM, that the new value is applied to DOM?

Upvotes: 1

Views: 78

Answers (2)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657058

You can listen to model.changes but this is also what Polymer does. To execute your code after Polymer added the elements to the DOM you can delay your code like

model.changes.listen((changes) {
  new Future(() => doSomethingAfterDomUpdate());
});

This way you give Polymer time to complete its updates.

Upvotes: 1

Robert
Robert

Reputation: 5662

  1. You have to use toObservable() on your map, otherwise new values will not be inserted.

  2. Why do you need to know when new values are updated in the DOM? If you really need it you can listen to the changes of the ObservableMap.

Upvotes: 1

Related Questions