Skip to content

Commit e424115

Browse files
committed
Refactor search service to more modern Ember
1 parent 6425dab commit e424115

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

app/services/search.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import Service, { inject as service } from '@ember/service';
22
import { restartableTask } from 'ember-concurrency';
3-
import { set } from '@ember/object';
4-
import { A as emberArray } from '@ember/array';
5-
// eslint-disable-next-line ember/no-computed-properties-in-native-classes
6-
import { alias } from '@ember/object/computed';
3+
import { tracked } from '@glimmer/tracking';
74

85
export default class SearchService extends Service {
96
@service('algolia') _algoliaService;
10-
@service('project') _projectService;
11-
12-
@alias('_projectService.version') _projectVersion;
7+
@service('project') projectService;
138

149
/** @type {?string} */
15-
_lastQueriedProjectVersion = null;
10+
#lastQueriedProjectVersion = null;
11+
12+
@tracked results = [];
1613

17-
results = emberArray();
14+
get projectVersion() {
15+
return this.projectService.version;
16+
}
1817

1918
search = restartableTask(async (query) => {
20-
const projectVersion = this._projectVersion;
19+
const projectVersion = this.projectVersion;
2120

2221
const params = {
2322
hitsPerPage: 15,
@@ -35,9 +34,10 @@ export default class SearchService extends Service {
3534
query,
3635
};
3736

38-
this._lastQueriedProjectVersion = projectVersion;
37+
this.#lastQueriedProjectVersion = projectVersion;
3938

40-
return set(this, 'results', await this.doSearch(searchObj, params));
39+
this.results = await this.doSearch(searchObj, params);
40+
return this.results;
4141
});
4242

4343
doSearch(searchObj, params) {
@@ -54,12 +54,12 @@ export default class SearchService extends Service {
5454
*/
5555
hasStaleResults() {
5656
return (
57-
this._lastQueriedProjectVersion !== null &&
58-
this._projectVersion !== this._lastQueriedProjectVersion
57+
this.#lastQueriedProjectVersion !== null &&
58+
this.projectVersion !== this.#lastQueriedProjectVersion
5959
);
6060
}
6161

6262
clearResults() {
63-
set(this, 'results', emberArray());
63+
this.results = [];
6464
}
6565
}

0 commit comments

Comments
 (0)