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

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

Issue 19492018: [mdv] Avoid observing placeholder arrays in TemplateIterator (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 abstract class _InputBinding { 7 abstract class _InputBinding {
8 // InputElement or SelectElement 8 // InputElement or SelectElement
9 final element; 9 final element;
10 PathObserver binding; 10 PathObserver binding;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 147 }
148 148
149 // The binding may wish to bind to an <option> which has not yet been 149 // The binding may wish to bind to an <option> which has not yet been
150 // produced by a child <template>. Furthermore, we may need to wait for 150 // produced by a child <template>. Furthermore, we may need to wait for
151 // <optgroup> iterating and then for <option>. 151 // <optgroup> iterating and then for <option>.
152 // 152 //
153 // Unlike the JavaScript MDV, we don't have a special "Object.observe" event 153 // Unlike the JavaScript MDV, we don't have a special "Object.observe" event
154 // loop to schedule on. (See the the "ensureScheduled" function: 154 // loop to schedule on. (See the the "ensureScheduled" function:
155 // https://github.com/Polymer/mdv/commit/9a51ad7ed74a292bf71662cea28acbd151f f65c8) 155 // https://github.com/Polymer/mdv/commit/9a51ad7ed74a292bf71662cea28acbd151f f65c8)
156 // 156 //
157 // Instead we use runAsync. Each <template repeat> needs a delay of 3: 157 // Instead we use runAsync. Each <template repeat> needs a delay of 3:
justinfagnani 2013/07/24 00:42:55 3 -> 2?
Jennifer Messerly 2013/07/24 00:52:58 Done.
158 // * once to happen after the child _TemplateIterator is created 158 // * once to happen after the child _TemplateIterator is created
159 // * once to be after _TemplateIterator.inputs CompoundBinding resolve 159 // * once to be after _TemplateIterator.inputs CompoundBinding resolve
160 // * once to be after _TemplateIterator._valueBinding PathObserver fires
161 // And then we need to do this delay sequence twice: 160 // And then we need to do this delay sequence twice:
162 // * once for OPTGROUP 161 // * once for OPTGROUP
163 // * once for OPTION. 162 // * once for OPTION.
164 // The resulting 2 * 3 is our maxRetries. 163 // The resulting 2 * 2 is our maxRetries.
165 var maxRetries = 6; 164 var maxRetries = 4;
166 delaySetSelectedIndex() { 165 delaySetSelectedIndex() {
167 if (newValue > element.length && --maxRetries >= 0) { 166 if (newValue > element.length && --maxRetries >= 0) {
168 runAsync(delaySetSelectedIndex); 167 runAsync(delaySetSelectedIndex);
169 } else { 168 } else {
170 element.selectedIndex = newValue; 169 element.selectedIndex = newValue;
171 } 170 }
172 } 171 }
173 172
174 runAsync(delaySetSelectedIndex); 173 runAsync(delaySetSelectedIndex);
175 } 174 }
176 175
177 void updateBinding(e) { 176 void updateBinding(e) {
178 binding.value = element.selectedIndex; 177 binding.value = element.selectedIndex;
179 } 178 }
180 179
181 // TODO(jmesserly,sigmund): I wonder how many bindings typically convert from 180 // TODO(jmesserly,sigmund): I wonder how many bindings typically convert from
182 // one type to another (e.g. value-as-number) and whether it is useful to 181 // one type to another (e.g. value-as-number) and whether it is useful to
183 // have something like a int/num binding converter (either as a base class or 182 // have something like a int/num binding converter (either as a base class or
184 // a wrapper). 183 // a wrapper).
185 static int _toInt(value) { 184 static int _toInt(value) {
186 if (value is String) return int.parse(value, onError: (_) => null); 185 if (value is String) return int.parse(value, onError: (_) => null);
187 return value is int ? value : null; 186 return value is int ? value : null;
188 } 187 }
189 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698