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

Side by Side Diff: pkg/template_binding/lib/src/text.dart

Issue 132403010: big update to observe, template_binding, polymer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 part of template_binding; 5 part of template_binding;
6 6
7 /** Extensions to the [Text] API. */ 7 /** Extensions to the [Text] API. */
8 class _TextExtension extends NodeBindExtension { 8 class _TextExtension extends NodeBindExtension {
9 _TextExtension(Text node) : super._(node); 9 _TextExtension(Text node) : super._(node);
10 10
11 NodeBinding bind(String name, model, [String path]) { 11 bind(String name, value, {bool oneTime: false}) {
12 // Dart note: 'text' instead of 'textContent' to match the DOM property. 12 // Dart note: 'text' instead of 'textContent' to match the DOM property.
13 if (name != 'text') { 13 if (name != 'text') {
14 return super.bind(name, model, path); 14 return super.bind(name, value, oneTime: oneTime);
15 } 15 }
16 if (oneTime) {
17 return _updateText(value);
18 }
19
16 unbind(name); 20 unbind(name);
17 return bindings[name] = new _TextBinding(_node, model, path); 21 _open(value, _updateText);
22 return bindings[name] = value;
23 }
24
25 _updateText(value) {
26 _node.text = _sanitizeValue(value);
18 } 27 }
19 } 28 }
20 29
21 class _TextBinding extends NodeBinding { 30 /** Called to sanitize the value before it is assigned into the property. */
22 _TextBinding(node, model, path) : super(node, 'text', model, path); 31 _sanitizeValue(value) => value == null ? '' : '$value';
23
24 void valueChanged(newValue) {
25 node.text = sanitizeBoundValue(newValue);
26 }
27 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698