From 0c204d17241ff6664b69aa8237a26803e24940b9 Mon Sep 17 00:00:00 2001 From: tatianag Date: Fri, 8 Apr 2016 19:33:00 -0700 Subject: [PATCH] SuggestBox - using Promise.resolve to process getSuggestions to treat promise and non-promise the same way --- src/firefly/js/ui/SuggestBoxInputField.jsx | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/firefly/js/ui/SuggestBoxInputField.jsx b/src/firefly/js/ui/SuggestBoxInputField.jsx index 0f78482097..3d8e5f7347 100644 --- a/src/firefly/js/ui/SuggestBoxInputField.jsx +++ b/src/firefly/js/ui/SuggestBoxInputField.jsx @@ -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}); } }