Remove race between multiple autocomplete requests (#4860)

Этот коммит содержится в:
Joram Wilander
2016-12-21 12:45:21 -05:00
коммит произвёл Harrison Healey
родитель 26e43c671c
Коммит cadc9e11e4
8 изменённых файлов: 80 добавлений и 20 удалений

Просмотреть файл

@@ -121,11 +121,6 @@ class SuggestionStore extends EventEmitter {
}
addSuggestions(id, terms, items, component, matchedPretext) {
if (!this.getPretext(id).endsWith(matchedPretext)) {
// These suggestions are out of date since the pretext has changed
return;
}
const suggestion = this.getSuggestions(id);
suggestion.terms.push(...terms);
@@ -222,6 +217,11 @@ class SuggestionStore extends EventEmitter {
suggestion.selection = suggestion.terms[selectionIndex];
}
checkIfPretextMatches(id, matchedPretext) {
const pretext = this.getPretext(id) || '';
return pretext.endsWith(matchedPretext);
}
handleEventPayload(payload) {
const {type, id, ...other} = payload.action;
@@ -241,9 +241,12 @@ class SuggestionStore extends EventEmitter {
this.emitSuggestionsChanged(id);
break;
case ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS:
this.clearSuggestions(id);
if (!this.checkIfPretextMatches(id, other.matchedPretext)) {
// These suggestions are out of date since the pretext has changed
return;
}
// ensure the matched pretext hasn't changed so that we don't receive suggestions for outdated pretext
this.clearSuggestions(id);
this.addSuggestions(id, other.terms, other.items, other.component, other.matchedPretext);
this.ensureSelectionExists(id);