在这个rxjs 示例中,atakeUntil
用于该switchMap
部分。我删除了它并且可观察的工作正常。
为什么在这个例子takeUntil
中 the和 thenextSearch$
是必要的?
@Injectable()
export class BookEffects {
@Effect()
search$: Observable<Action> = this.actions$
.ofType(book.ActionTypes.SEARCH)
.debounceTime(300)
.map(toPayload)
.switchMap(query => {
if (query === '') {
return empty();
}
const nextSearch$ = this.actions$.ofType(book.ActionTypes.SEARCH).skip(1);
return this.googleBooks.searchBooks(query)
.takeUntil(nextSearch$)
.map(books => new book.SearchCompleteAction(books))
.catch(() => of(new book.SearchCompleteAction([])));
});
constructor(private actions$: Actions, private googleBooks: GoogleBooksService) { }
}