Skip to content

Commit 96770fc

Browse files
gnpricechrisbobbe
authored andcommitted
autocomplete [nfc]: Record query within _computeResults
This method, and its caller _startSearch, already assume that the query they're given is the current `_query`. Remove the parameter, to simplify away redundancy and avoid possible confusion on how the two query values relate.
1 parent 540b5da commit 96770fc

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/model/autocomplete.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ abstract class AutocompleteView<QueryT extends AutocompleteQuery, ResultT extend
201201
set query(QueryT? query) {
202202
_query = query;
203203
if (query != null) {
204-
_startSearch(query);
204+
_startSearch();
205205
}
206206
}
207207

@@ -210,15 +210,15 @@ abstract class AutocompleteView<QueryT extends AutocompleteQuery, ResultT extend
210210
/// This will redo the search from scratch for the current query, if any.
211211
void reassemble() {
212212
if (_query != null) {
213-
_startSearch(_query!);
213+
_startSearch();
214214
}
215215
}
216216

217217
Iterable<ResultT> get results => _results;
218218
List<ResultT> _results = [];
219219

220-
Future<void> _startSearch(QueryT query) async {
221-
final newResults = await _computeResults(query);
220+
Future<void> _startSearch() async {
221+
final newResults = await _computeResults();
222222
if (newResults == null) {
223223
// Query was old; new search is in progress. Or, no listeners to notify.
224224
return;
@@ -228,7 +228,9 @@ abstract class AutocompleteView<QueryT extends AutocompleteQuery, ResultT extend
228228
notifyListeners();
229229
}
230230

231-
Future<List<ResultT>?> _computeResults(QueryT query) async {
231+
Future<List<ResultT>?> _computeResults() async {
232+
assert(_query != null);
233+
final query = _query!;
232234
final List<ResultT> results = [];
233235
final Iterable<CandidateT> data = getSortedItemsToTest();
234236

@@ -582,7 +584,7 @@ class TopicAutocompleteView extends AutocompleteView<TopicAutocompleteQuery, Top
582584
final result = await getStreamTopics(store.connection, streamId: streamId);
583585
_topics = result.topics.map((e) => e.name);
584586
_isFetching = false;
585-
if (_query != null) _startSearch(_query!);
587+
if (_query != null) _startSearch();
586588
}
587589

588590
@override

0 commit comments

Comments
 (0)