Refactor song selection to a service

This commit is contained in:
Geomitron
2020-05-10 19:53:53 -04:00
parent 8a4620d771
commit e41d69da46
8 changed files with 143 additions and 65 deletions

View File

@@ -22,14 +22,23 @@ export class SearchService {
this.results = this.trimLastChart(await this.electronService.invoke('song-search', this.currentQuery))
this.awaitingResults = false
this.newResultsEmitter.emit(this.results)
this.resultsChangedEmitter.emit(this.results)
this.newResultsEmitter.emit(this.results)
}
/**
* Event emitted when new search results are returned
* or when more results are added to an existing search.
* (emitted before `onNewSearch`)
*/
onSearchChanged(callback: (results: SongResult[]) => void) {
this.resultsChangedEmitter.subscribe(callback)
}
/**
* Event emitted when a new search query is typed in.
* (emitted after `onSearchChanged`)
*/
onNewSearch(callback: (results: SongResult[]) => void) {
this.newResultsEmitter.subscribe(callback)
}