Skip to content

Commit

Permalink
SuggestBox - using Promise.resolve to process getSuggestions to treat…
Browse files Browse the repository at this point in the history
… promise and non-promise the same way
  • Loading branch information
tgoldina committed Apr 9, 2016
1 parent cb9e82b commit 0c204d1
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/firefly/js/ui/SuggestBoxInputField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,16 @@ class SuggestBoxInputFieldView extends Component {

updateSuggestions(displayValue) {
const arrayOrPromise = this.props.getSuggestions(displayValue);
if (arrayOrPromise.then) {
this.suggestionsPromise = arrayOrPromise;
arrayOrPromise.then((suggestions) => {
// make sure the suggestions are still relevant
if (arrayOrPromise === this.suggestionsPromise) {
this.setState({isOpen: true, suggestions: arrayOrPromise});
}
}).catch(err => logError(e))
} else if (isArray(arrayOrPromise) && arrayOrPromise.length>0) {
this.setState({isOpen: true, suggestions: arrayOrPromise});
}
this.suggestionsPromise = arrayOrPromise;
Promise.resolve(arrayOrPromise).then((suggestions) => {
// make sure the suggestions are still relevant when promise returns
if (arrayOrPromise === this.suggestionsPromise && isArray(suggestions) && suggestions.length > 0) {
this.setState({isOpen: true, suggestions});
}
}).catch(err => logError(err))
}


changeHighlighted(newHighlightedIdx) {
if (newHighlightedIdx !== this.state.highlightedIdx) { this.setState({highlightedIdx: newHighlightedIdx}); }
}
Expand Down

0 comments on commit 0c204d1

Please sign in to comment.