react-super-select
Advanced tools
Comparing version 0.1.15 to 0.1.16
@@ -222,4 +222,19 @@ // © Scotland Stephenson 2015 | ||
// If parent page updates the data source, reset the control with some defaults and the new dataSource. | ||
// If parent page updates the data source, reset all control state values which are derived from props. | ||
// Reset some state defaults and dataSource related fields if dataSource changed. | ||
componentWillReceiveProps: function componentWillReceiveProps(nextProps) { | ||
var newState = {}; | ||
if (!_.isEqual(nextProps.initialValue, this.props.initialValue)) { | ||
newState.value = this._buildInitialValue(nextProps); | ||
} | ||
if (!_.isUndefined(nextProps.optionLabelKey) && nextProps.optionLabelKey !== this.props.optionLabelKey) { | ||
newState.labelKey = nextProps.optionLabelKey; | ||
} | ||
if (!_.isUndefined(nextProps.optionValueKey) && nextProps.optionValueKey !== this.props.optionValueKey) { | ||
newState.valueKey = nextProps.optionValueKey; | ||
} | ||
if (!_.isEqual(this.props.dataSource, nextProps.dataSource)) { | ||
@@ -229,11 +244,12 @@ | ||
this.setState({ | ||
newState = _.extend(newState, { | ||
data: this._configureDataSource(nextProps.dataSource), | ||
rawDataSource: nextProps.dataSource, | ||
focusedId: undefined, | ||
labelKey: nextProps.optionLabelKey || 'name', | ||
lastOptionId: _.isArray(nextProps.dataSource) && nextProps.dataSource.length > 0 ? nextProps.dataSource.length - 1 : undefined, | ||
valueKey: nextProps.optionValueKey || 'id' | ||
}); | ||
lastOptionId: _.isArray(nextProps.dataSource) && nextProps.dataSource.length > 0 ? nextProps.dataSource.length - 1 : undefined }); | ||
} | ||
if (!_.isEmpty(newState)) { | ||
this.setState(newState); | ||
} | ||
}, | ||
@@ -324,8 +340,9 @@ | ||
// calculate the initial value for the control from props | ||
_buildInitialValue: function _buildInitialValue() { | ||
// calculate the initial value for the control from props, componentWillReceiveProps will call passing nextProps | ||
_buildInitialValue: function _buildInitialValue(props) { | ||
props = props || this.props; | ||
var initialValue = []; | ||
if (!_.isUndefined(this.props.initialValue)) { | ||
initialValue = _.isArray(this.props.initialValue) ? this.props.initialValue : [this.props.initialValue]; | ||
if (!_.isUndefined(props.initialValue)) { | ||
initialValue = _.isArray(props.initialValue) ? props.initialValue : [props.initialValue]; | ||
@@ -332,0 +349,0 @@ if (!this._isMultiSelect()) { |
{ | ||
"name": "react-super-select", | ||
"version": "0.1.15", | ||
"version": "0.1.16", | ||
"description": "A flexible replacement for the html select control built with React", | ||
@@ -5,0 +5,0 @@ "main": "./lib/react-super-select.js", |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
1379
65262
1
0