OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library bindings_test; | 5 library bindings_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 | 9 |
10 import 'package:observe/observe.dart'; | 10 import 'package:observe/observe.dart'; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // ... or on the next animation frame. | 123 // ... or on the next animation frame. |
124 expect(el.selectionStart, 4); | 124 expect(el.selectionStart, 4); |
125 expect(el.selectionEnd, 4); | 125 expect(el.selectionEnd, 4); |
126 }).then(_afterTimeout).then((_) { | 126 }).then(_afterTimeout).then((_) { |
127 // ... or later. | 127 // ... or later. |
128 expect(el.selectionStart, 4); | 128 expect(el.selectionStart, 4); |
129 expect(el.selectionEnd, 4); | 129 expect(el.selectionEnd, 4); |
130 }); | 130 }); |
131 }); | 131 }); |
132 | 132 |
| 133 test('detects changes to ObservableList', () { |
| 134 var list = new ObservableList.from([1, 2, 3]); |
| 135 var template = templateBind(new Element.html( |
| 136 '<template>{{x[1]}}</template>')); |
| 137 var model = new NotifyModel(list); |
| 138 testDiv.append(template.createInstance(model, new PolymerExpressions())); |
| 139 |
| 140 return new Future(() { |
| 141 expect(testDiv.text, '2'); |
| 142 list[1] = 10; |
| 143 }).then(_nextMicrotask).then((_) { |
| 144 expect(testDiv.text, '10'); |
| 145 list[1] = 11; |
| 146 }).then(_nextMicrotask).then((_) { |
| 147 expect(testDiv.text, '11'); |
| 148 list[0] = 9; |
| 149 }).then(_nextMicrotask).then((_) { |
| 150 expect(testDiv.text, '11'); |
| 151 list.removeAt(0); |
| 152 }).then(_nextMicrotask).then((_) { |
| 153 expect(testDiv.text, '3'); |
| 154 list.add(90); |
| 155 list.removeAt(0); |
| 156 }).then(_nextMicrotask).then((_) { |
| 157 expect(testDiv.text, '90'); |
| 158 }); |
| 159 }); |
133 | 160 |
134 test('detects changes to ObservableMap keys/values', () { | 161 test('detects changes to ObservableMap keys/values', () { |
135 var map = new ObservableMap.from({'a': 1, 'b': 2}); | 162 var map = new ObservableMap.from({'a': 1, 'b': 2}); |
136 var template = templateBind(new Element.html('<template>' | 163 var template = templateBind(new Element.html('<template>' |
137 '<template repeat="{{k in x.keys}}">{{k}}:{{x[k]}},</template>' | 164 '<template repeat="{{k in x.keys}}">{{k}}:{{x[k]}},</template>' |
138 '</template>')); | 165 '</template>')); |
139 var model = new NotifyModel(map); | 166 var model = new NotifyModel(map); |
140 testDiv.append(template.createInstance(model, new PolymerExpressions())); | 167 testDiv.append(template.createInstance(model, new PolymerExpressions())); |
141 | 168 |
142 return new Future(() { | 169 return new Future(() { |
(...skipping 16 matching lines...) Expand all Loading... |
159 @reflectable | 186 @reflectable |
160 class NotifyModel extends ChangeNotifier { | 187 class NotifyModel extends ChangeNotifier { |
161 var _x; | 188 var _x; |
162 NotifyModel([this._x]); | 189 NotifyModel([this._x]); |
163 | 190 |
164 get x => _x; | 191 get x => _x; |
165 set x(value) { | 192 set x(value) { |
166 _x = notifyPropertyChange(#x, _x, value); | 193 _x = notifyPropertyChange(#x, _x, value); |
167 } | 194 } |
168 } | 195 } |
OLD | NEW |