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

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

Issue 19771010: implement dirty checking for @observable objects (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 [SelectElement] API. */ 7 /** Extensions to the [SelectElement] API. */
8 class _SelectElementExtension extends _ElementExtension { 8 class _SelectElementExtension extends _ElementExtension {
9 _SelectElementExtension(SelectElement node) : super(node); 9 _SelectElementExtension(SelectElement node) : super(node);
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 SelectElement get element => super.element; 44 SelectElement get element => super.element;
45 45
46 void valueChanged(value) { 46 void valueChanged(value) {
47 var newValue = _toInt(value); 47 var newValue = _toInt(value);
48 if (newValue <= element.length) { 48 if (newValue <= element.length) {
49 element.selectedIndex = newValue; 49 element.selectedIndex = newValue;
50 return; 50 return;
51 } 51 }
52 52
53 // The binding may wish to bind to an <option> which has not yet been 53 // The binding may wish to bind to an <option> which has not yet been
54 // produced by a child <template>. Delay a maximum of twice -- once for 54 // produced by a child <template>. Furthermore, we may need to wait for
55 // iterating <optgroup> and once for <option>. 55 // <optgroup> iterating and then for <option>.
56 var maxRetries = 2; 56 //
57 // Unlike the JavaScript MDV, we don't have a special "Object.observe" event
58 // loop to schedule on. (See the the "ensureScheduled" function:
59 // https://github.com/Polymer/mdv/commit/9a51ad7ed74a292bf71662cea28acbd151f f65c8)
60 //
61 // Instead we use runAsync. Each <template repeat> needs a delay of 3:
62 // * once to happen after the child _TemplateIterator is created
63 // * once to be after _TemplateIterator.inputs CompoundBinding resolve
64 // * once to be after _TemplateIterator._valueBinding PathObserver fires
65 // And then we need to do this delay sequence twice:
66 // * once for OPTGROUP
67 // * once for OPTION.
68 // The resulting 2 * 3 is our maxRetries.
69 var maxRetries = 6;
57 delaySetSelectedIndex() { 70 delaySetSelectedIndex() {
58 if (newValue > element.length && --maxRetries >= 0) { 71 if (newValue > element.length && --maxRetries >= 0) {
59 runAsync(delaySetSelectedIndex); 72 runAsync(delaySetSelectedIndex);
60 } else { 73 } else {
61 element.selectedIndex = newValue; 74 element.selectedIndex = newValue;
62 } 75 }
63 } 76 }
64 77
65 // TODO(jmesserly): we aren't matching MDV here. They schedule "model=" to
66 // happen async and then delay using the same scheduler. By using "runAsync"
67 // we're going to happen quite a bit later.
68 // We need to port the "ensureScheduled" function:
69 // https://github.com/Polymer/mdv/commit/9a51ad7ed74a292bf71662cea28acbd151f f65c8
70 runAsync(delaySetSelectedIndex); 78 runAsync(delaySetSelectedIndex);
71 } 79 }
72 80
73 void updateBinding(e) { 81 void updateBinding(e) {
74 binding.value = element.selectedIndex; 82 binding.value = element.selectedIndex;
75 } 83 }
76 84
77 // TODO(jmesserly,sigmund): I wonder how many bindings typically convert from 85 // TODO(jmesserly,sigmund): I wonder how many bindings typically convert from
78 // one type to another (e.g. value-as-number) and whether it is useful to 86 // one type to another (e.g. value-as-number) and whether it is useful to
79 // have something like a int/num binding converter (either as a base class or 87 // have something like a int/num binding converter (either as a base class or
80 // a wrapper). 88 // a wrapper).
81 static int _toInt(value) { 89 static int _toInt(value) {
82 if (value is String) return int.parse(value, onError: (_) => null); 90 if (value is String) return int.parse(value, onError: (_) => null);
83 return value is int ? value : null; 91 return value is int ? value : null;
84 } 92 }
85 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698