Refactor updateOptions to take value
Ben Alpert committed
Feb 5, 2014 at 11:46 UTC
c7dd8d4217f7f3535b09627b091007031327fec5
1 file changed
+13
-13
src/browser/dom/components/ReactDOMSelect.js
+13
-13
@@ -56,19 +56,15 @@ function selectValueType(props, propName, componentName) {
56
57
/**
58
* If `value` is supplied, updates <option> elements on mount and update.
59
- * @param {boolean} force If true, updates the value even on an uncontrolled
60
- * component.
59
+ * @param {ReactComponent} component Instance of ReactDOMSelect
60
+ * @param {?*} propValue For uncontrolled components, null/undefined. For
61
+ * controlled components, a string (or with `multiple`, a list of strings).
62
* @private
63
*/
63
-function updateOptions(force) {
64
- /*jshint validthis:true */
65
- var multiple = this.props.multiple;
66
- var propValue = LinkedValueUtils.getValue(this);
67
- if (propValue == null && !force) {
68
- return;
69
- }
70
- var value = propValue != null ? propValue : this.state.value;
71
- var options = this.getDOMNode().options;
64
+function updateOptions(component, propValue) {
65
+ var multiple = component.props.multiple;
66
+ var value = propValue != null ? propValue : component.state.value;
67
+ var options = component.getDOMNode().options;
68
var selectedValue, i, l;
69
if (multiple) {
70
selectedValue = {};
@@ -142,11 +138,15 @@ var ReactDOMSelect = ReactCompositeComponent.createClass({
138
},
139
140
componentDidMount: function() {
145
- updateOptions.call(this, true);
141
+ var value = LinkedValueUtils.getValue(this);
142
+ updateOptions(this, value);
143
},
144
145
componentDidUpdate: function() {
149
- updateOptions.call(this, false);
146
+ var value = LinkedValueUtils.getValue(this);
147
+ if (value != null) {
148
+ updateOptions(this, value);
149
+ }
150
},
151
152
_handleChange: function(event) {