Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(899)

Side by Side Diff: pkg/template_binding/test/custom_element_bindings_test.dart

Issue 42433002: port Node.bind to bd0a0591920da9091b326627a46a104a92c7efe7 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 template_binding.test.custom_element_bindings_test; 5 library template_binding.test.custom_element_bindings_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'package:custom_element/polyfill.dart'; 9 import 'package:custom_element/polyfill.dart';
10 import 'package:template_binding/template_binding.dart'; 10 import 'package:template_binding/template_binding.dart';
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 /** Demonstrates a custom element overriding bind/unbind/unbindAll. */ 159 /** Demonstrates a custom element overriding bind/unbind/unbindAll. */
160 class MyCustomElement extends HtmlElement implements NodeBindExtension { 160 class MyCustomElement extends HtmlElement implements NodeBindExtension {
161 Point myPoint; 161 Point myPoint;
162 Monster scaryMonster; 162 Monster scaryMonster;
163 163
164 factory MyCustomElement() => new Element.tag('my-custom-element'); 164 factory MyCustomElement() => new Element.tag('my-custom-element');
165 165
166 MyCustomElement.created() : super.created(); 166 MyCustomElement.created() : super.created();
167 167
168 NodeBinding createBinding(String name, model, String path) { 168 NodeBinding bind(String name, model, [String path]) {
169 switch (name) { 169 switch (name) {
170 case 'my-point': 170 case 'my-point':
171 case 'scary-monster': 171 case 'scary-monster':
172 return new _MyCustomBinding(this, name, model, path); 172 attributes.remove(name);
173 unbind(name);
174 return bindings[name] = new _MyCustomBinding(this, name, model, path);
173 } 175 }
174 return nodeBindFallback(this).createBinding(name, model, path); 176 return nodeBindFallback(this).bind(name, model, path);
175 } 177 }
176 178
177 bind(name, model, path) => nodeBindFallback(this).bind(name, model, path);
178 unbind(name) => nodeBindFallback(this).unbind(name); 179 unbind(name) => nodeBindFallback(this).unbind(name);
179 unbindAll() => nodeBindFallback(this).unbindAll(); 180 unbindAll() => nodeBindFallback(this).unbindAll();
181 get bindings => nodeBindFallback(this).bindings;
180 } 182 }
181 183
182 class _MyCustomBinding extends NodeBinding { 184 class _MyCustomBinding extends NodeBinding {
183 _MyCustomBinding(MyCustomElement node, property, model, path) 185 _MyCustomBinding(MyCustomElement node, property, model, path)
184 : super(node, property, model, path) { 186 : super(node, property, model, path) {
185 187
186 node.attributes.remove(property); 188 node.attributes.remove(property);
187 } 189 }
188 190
189 MyCustomElement get node => super.node; 191 MyCustomElement get node => super.node;
190 192
191 void boundValueChanged(newValue) { 193 void valueChanged(newValue) {
192 if (property == 'my-point') node.myPoint = newValue; 194 if (property == 'my-point') node.myPoint = newValue;
193 if (property == 'scary-monster') node.scaryMonster = newValue; 195 if (property == 'scary-monster') node.scaryMonster = newValue;
194 } 196 }
195 } 197 }
196 198
197 199
198 /** 200 /**
199 * Demonstrates a custom element can override attributes []= and remove. 201 * Demonstrates a custom element can override attributes []= and remove.
200 * and see changes that the data binding system is making to the attributes. 202 * and see changes that the data binding system is making to the attributes.
201 */ 203 */
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 239
238 void addAll(Map<K, V> other) => _map.addAll(other); 240 void addAll(Map<K, V> other) => _map.addAll(other);
239 void clear() => _map.clear(); 241 void clear() => _map.clear();
240 void forEach(void f(K key, V value)) => _map.forEach(f); 242 void forEach(void f(K key, V value)) => _map.forEach(f);
241 Iterable<K> get keys => _map.keys; 243 Iterable<K> get keys => _map.keys;
242 Iterable<V> get values => _map.values; 244 Iterable<V> get values => _map.values;
243 int get length => _map.length; 245 int get length => _map.length;
244 bool get isEmpty => _map.isEmpty; 246 bool get isEmpty => _map.isEmpty;
245 bool get isNotEmpty => _map.isNotEmpty; 247 bool get isNotEmpty => _map.isNotEmpty;
246 } 248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698