[英]Modify Observable with another Observable and return the initial Observable
[英]Return observable depending on another observable condition
我需要根據另一個可觀察的條件返回可觀察的數據,因此,如果存儲中的ID不同,則如果不發送任何更新,則將更新的數據發送到外部可觀察的數據,我需要此功能來支持多選項卡,因此每個選項卡都有其自身的加載,並且不會影響其他選項卡,因此僅當search_id
更改時,此代碼才返回數據,如果沒有更改,我們應該在外部可觀察到的位置返回什么?
this.data$ = this.getTopData$('book').pipe(
map(data => {
this.store
.select(currentSearchSelector)
.pipe(bufferCount(2))
.subscribe(([previousSearch, currentSearch]) => {
if ( previousSearch.id !== currentSearch.id ) {
return data;
}else
{
//what should I return here?
}
})
})
),
如果我按原樣返回數據,則其他選項卡中的小部件會感覺到更改並在其他選項卡更改搜索時加載其自身的數據。
我整理了一下代碼,可以使用never()
不會向流中發送任何內容,因此視圖上不會進行任何更新。
this.getTopData$('book').pipe(
switchMap(data =>this.store.select(currentSearchSelector).pipe(bufferCount(2))),
switchMap(([previousSearch, currentSearch]) => {
if ( previousSearch.id !== currentSearch.id ) {
return of(data);
}
else return never()
}})
).subscribe()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.