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

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

Issue 20149004: [mdv] implement Node.createBinding and Node.createBindings (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 mdv; 5 part of mdv;
6 6
7 /** Extensions to the [Text] API. */ 7 /** Extensions to the [Text] API. */
8 class _TextExtension extends _NodeExtension { 8 class _TextExtension extends _NodeExtension {
9 _TextExtension(Text node) : super(node); 9 _TextExtension(Text node) : super(node);
10 10
11 Text get node => super.node; 11 NodeBinding createBinding(String name, model, String path) {
12 12 if (name == 'text') return new _TextBinding(node, model, path);
13 StreamSubscription _textBinding; 13 return super.createBinding(name, model, path);
14
15 void bind(String name, model, String path) {
16 if (name != 'text') {
17 super.bind(name, model, path);
18 return;
19 }
20
21 unbind('text');
22
23 _textBinding = new PathObserver(model, path).bindSync((value) {
24 node.text = value == null ? '' : '$value';
25 });
26 }
27
28 void unbind(String name) {
29 if (name != 'text') {
30 super.unbind(name);
31 return;
32 }
33
34 if (_textBinding == null) return;
35
36 _textBinding.cancel();
37 _textBinding = null;
38 }
39
40 void unbindAll() {
41 unbind('text');
42 super.unbindAll();
43 } 14 }
44 } 15 }
16
17 class _TextBinding extends NodeBinding {
18 _TextBinding(node, model, path) : super(node, 'text', model, path);
19
20 void boundValueChanged(newValue) {
21 node.text = sanitizeBoundValue(newValue);
22 }
23 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698