Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 extends NodeBinding { | 7 abstract class _InputBinding extends NodeBinding { |
| 8 StreamSubscription _eventSub; | 8 StreamSubscription _eventSub; |
| 9 | 9 |
| 10 _InputBinding(node, name, model, path): super(node, name, model, path) { | 10 _InputBinding(node, name, model, path): super(node, name, model, path) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 } | 144 } |
| 145 | 145 |
| 146 // The binding may wish to bind to an <option> which has not yet been | 146 // The binding may wish to bind to an <option> which has not yet been |
| 147 // produced by a child <template>. Furthermore, we may need to wait for | 147 // produced by a child <template>. Furthermore, we may need to wait for |
| 148 // <optgroup> iterating and then for <option>. | 148 // <optgroup> iterating and then for <option>. |
| 149 // | 149 // |
| 150 // Unlike the JavaScript MDV, we don't have a special "Object.observe" event | 150 // Unlike the JavaScript MDV, we don't have a special "Object.observe" event |
| 151 // loop to schedule on. (See the the "ensureScheduled" function: | 151 // loop to schedule on. (See the the "ensureScheduled" function: |
| 152 // https://github.com/Polymer/mdv/commit/9a51ad7ed74a292bf71662cea28acbd151f f65c8) | 152 // https://github.com/Polymer/mdv/commit/9a51ad7ed74a292bf71662cea28acbd151f f65c8) |
| 153 // | 153 // |
| 154 // Instead we use runAsync. Each <template repeat> needs a delay of 2: | 154 // Instead we use scheduleMicrotask. Each <template repeat> needs a delay of |
| 155 // 2: | |
|
Lasse Reichstein Nielsen
2013/10/07 07:17:03
This is extremely fragile, and depends on the exac
floitsch
2013/10/10 16:00:36
Filed dartbug.com/13968
| |
| 155 // * once to happen after the child _TemplateIterator is created | 156 // * once to happen after the child _TemplateIterator is created |
| 156 // * once to be after _TemplateIterator.inputs CompoundBinding resolve | 157 // * once to be after _TemplateIterator.inputs CompoundBinding resolve |
| 157 // And then we need to do this delay sequence twice: | 158 // And then we need to do this delay sequence twice: |
| 158 // * once for OPTGROUP | 159 // * once for OPTGROUP |
| 159 // * once for OPTION. | 160 // * once for OPTION. |
| 160 // The resulting 2 * 2 is our maxRetries. | 161 // The resulting 2 * 2 is our maxRetries. |
| 161 var maxRetries = 4; | 162 var maxRetries = 4; |
| 162 delaySetSelectedIndex() { | 163 delaySetSelectedIndex() { |
| 163 if (newValue > node.length && --maxRetries >= 0) { | 164 if (newValue > node.length && --maxRetries >= 0) { |
| 164 runAsync(delaySetSelectedIndex); | 165 scheduleMicrotask(delaySetSelectedIndex); |
| 165 } else { | 166 } else { |
| 166 node.selectedIndex = newValue; | 167 node.selectedIndex = newValue; |
| 167 } | 168 } |
| 168 } | 169 } |
| 169 | 170 |
| 170 runAsync(delaySetSelectedIndex); | 171 scheduleMicrotask(delaySetSelectedIndex); |
| 171 } | 172 } |
| 172 | 173 |
| 173 void nodeValueChanged(e) { | 174 void nodeValueChanged(e) { |
| 174 value = node.selectedIndex; | 175 value = node.selectedIndex; |
| 175 } | 176 } |
| 176 | 177 |
| 177 // TODO(jmesserly,sigmund): I wonder how many bindings typically convert from | 178 // TODO(jmesserly,sigmund): I wonder how many bindings typically convert from |
| 178 // one type to another (e.g. value-as-number) and whether it is useful to | 179 // one type to another (e.g. value-as-number) and whether it is useful to |
| 179 // have something like a int/num binding converter (either as a base class or | 180 // have something like a int/num binding converter (either as a base class or |
| 180 // a wrapper). | 181 // a wrapper). |
| 181 static int _toInt(value) { | 182 static int _toInt(value) { |
| 182 if (value is String) return int.parse(value, onError: (_) => null); | 183 if (value is String) return int.parse(value, onError: (_) => null); |
| 183 return value is int ? value : null; | 184 return value is int ? value : null; |
| 184 } | 185 } |
| 185 } | 186 } |
| OLD | NEW |