Cleaned up isValueAnObject check
parent
3d4d93bc71
commit
d38abd1a91
|
@ -68,20 +68,12 @@ const factory = (Chip, Input) => {
|
|||
isValueAnObject: false
|
||||
};
|
||||
|
||||
componentDidMount () {
|
||||
this.setIsValueAnObject();
|
||||
}
|
||||
|
||||
componentWillReceiveProps (nextProps) {
|
||||
if (!this.props.multiple) {
|
||||
this.setState({
|
||||
query: this.query(nextProps.value)
|
||||
});
|
||||
}
|
||||
|
||||
if (nextProps.multiple && this.props.value !== nextProps.value) {
|
||||
this.setIsValueAnObject();
|
||||
}
|
||||
}
|
||||
|
||||
shouldComponentUpdate (nextProps, nextState) {
|
||||
|
@ -251,7 +243,7 @@ const factory = (Chip, Input) => {
|
|||
|
||||
if (!vals) vals = [];
|
||||
|
||||
if (this.props.showSelectedWhenNotInSource && this.state.isValueAnObject) {
|
||||
if (this.props.showSelectedWhenNotInSource && this.isValueAnObject()) {
|
||||
return new Map(Object.entries(vals));
|
||||
}
|
||||
|
||||
|
@ -271,7 +263,7 @@ const factory = (Chip, Input) => {
|
|||
const source = this.source();
|
||||
const newValue = target === void 0 ? event.target.id : target;
|
||||
|
||||
if (this.state.isValueAnObject) {
|
||||
if (this.isValueAnObject()) {
|
||||
const newItem = Array.from(source).reduce((obj, [k, value]) => {
|
||||
if (k === newValue) {
|
||||
obj[k] = value;
|
||||
|
@ -291,7 +283,7 @@ const factory = (Chip, Input) => {
|
|||
|
||||
values.delete(key);
|
||||
|
||||
if (this.state.isValueAnObject) {
|
||||
if (this.isValueAnObject()) {
|
||||
return this.handleChange(this.mapToObject(values), event);
|
||||
}
|
||||
|
||||
|
@ -299,10 +291,8 @@ const factory = (Chip, Input) => {
|
|||
}
|
||||
}
|
||||
|
||||
setIsValueAnObject () {
|
||||
this.setState({
|
||||
isValueAnObject: !Array.isArray(this.props.value) && typeof this.props.value === 'object'
|
||||
});
|
||||
isValueAnObject () {
|
||||
return !Array.isArray(this.props.value) && typeof this.props.value === 'object';
|
||||
}
|
||||
|
||||
mapToObject (map) {
|
||||
|
|
Loading…
Reference in New Issue