typescript 秋田books.service.ts

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript 秋田books.service.ts相关的知识,希望对你有一定的参考价值。

export class BooksService {
  constructor(
    private bookStore: BooksStore,
    private bookQuery: BooksQuery,
    private googleService: GoogleBooksService
  ) { }

  searchBooks(searchTerm: string) {
    this.bookStore.setLoading(true);
    this.googleService.searchBooks(searchTerm).subscribe(books => {
      const nonCollection = this.bookQuery.nonCollectionBooks;
      this.bookStore.remove([...nonCollection]);
      this.add(books);
      this.bookStore.updateResultIds(books.map(({ id }) => id));
      this.bookStore.setLoading(false);
    });
  }

  updateSearchTerm(searchTerm: string) {
    this.bookStore.updateSearchTerm(searchTerm);
  }

  setActive(id: ID) {
    this.bookStore.setActive(id);
  }

  add(books: Book[]) {
    this.bookStore.add(books);
  }

  loadBooksToStore() {
    const books$ = this.bookQuery.collection.map(id =>this.googleService.retrieveBook(id));
    forkJoin(books$).subscribe(books => this.add(books));
  }

  updateCollection(bookId: ID) {
    this.bookStore.updateCollection(bookId);
  }
  
}

以上是关于typescript 秋田books.service.ts的主要内容,如果未能解决你的问题,请参考以下文章

typescript 秋田ViewBookPageComponent.ts

typescript 秋田CollectionPageComponent.ts

typescript 秋田books.service.ts

typescript 秋田books.query.ts

typescript 秋田books.store.ts

typescript 秋田app.component.ts