dart-archive / observe

Support for marking objects as observable, and getting notifications when those objects are mutated
https://pub.dartlang.org/packages/observe
BSD 3-Clause "New" or "Revised" License
13 stars 6 forks source link

can't observe list update in event #55

Closed DartBot closed 9 years ago

DartBot commented 9 years ago

Originally opened as dart-lang/sdk#15826

This issue was originally filed by joo...@gmail.com


<!DOCTYPE html>

<html>   <head>     <meta charset="utf-8">     <title>Sample app</title>     <script src="packages/browser/dart.js"></script>   </head>   <body>     <polymer-element name="my-element">       <template>         <table>           <tbody>             <tr template repeat="{{v in listO}}">               <td>{{v[0]}}</td>             </tr>           </tbody>         </table><br>                  <button on-click="{{test}}">test</button>       </template>       <script type="application/dart">         import 'package:polymer/polymer.dart';         import 'dart:html';                  void main() {           initPolymer();         }

        @­CustomTag('my-element')         class MyElement extends PolymerElement {           @­observable List<String> listO = toObservable(['1', '2']);

          MyElement.created() : super.created() {             listO.add('3');           }

          void test(Event event, var detail, Node target) {             listO[0] = '11';             listO.add('4');             window.alert(listO .toString());           }         }       </script>     </polymer-element>          <my-element></my-element>

  </body> </html>

above sample enter show 1 2 3, click test button show 1 2 3 4, but correct should show 11 2 3 4. where problems? observable list or repeat break?

sdk: 1.1.0-dev.5.0 observe: 0.9.3 polymer: 0.9.3+3 run on chromium by dart vm


Attachments: [Screenshot from 2013-12-30 17:38:45.png](https://storage.googleapis.com/google-code-attachments/dart/issue-15826/comment-0/Screenshot from 2013-12-30 17:38:45.png) (6.33 KB) [Screenshot from 2013-12-30 17:40:34.png](https://storage.googleapis.com/google-code-attachments/dart/issue-15826/comment-0/Screenshot from 2013-12-30 17:40:34.png) (27.21 KB)

DartBot commented 9 years ago

This comment was originally written by joo.t...@gmail.com


I am retry, observable list add or remove item can correct observe, but update item value can't observe changed.

DartBot commented 9 years ago

Comment by sigmundch


Added Area-Polymer, Library-Observe, Triaged labels.

DartBot commented 9 years ago

Comment by anders-sandholm


Removed Library-Observe label. Added Pkg-Observe label.

DartBot commented 9 years ago

Comment by jmesserly


Removed Area-Polymer label. Added Area-Pkg label.

DartBot commented 9 years ago

Comment by sigmundch


This seems to be working now with the current polymer packages (0.11.0, etc)

I did have to fix one thing in the example, instead of {{v[0]}} I use {{v}}. This is because v[0] is reading the first character of the string, so when you update to '11' the result is still '1'.

Alternatively, if you keep v[0], but you set the value to '71', then the template correctly displays '7'.


Added AssumedStale label.