本文整理匯總了TypeScript中rxjs/operators.endWith函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript endWith函數的具體用法?TypeScript endWith怎麽用?TypeScript endWith使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了endWith函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: addLoadingCount
function addLoadingCount(count$: Observable<number>) {
count$
.pipe(
distinctUntilChanged(),
tap(count => {
if (count < 0) {
throw new Error(
'Observables passed to loadingCount.add() must only emit positive numbers'
);
}
}),
// use takeUntil() so that we can finish each stream on stop() the same way we do when they complete,
// by removing the previous count from the total
takeUntil(stop$),
endWith(0),
startWith(0),
pairwise(),
map(([prev, next]) => next - prev)
)
.subscribe({
next: delta => {
loadingCount$.next(loadingCount$.getValue() + delta);
},
error: error => {
if (fatalErrors) {
fatalErrors.add(error);
}
},
});
}
示例2: it
it('should accept scheduler as last argument with multiple value', () => {
const e1 = hot('-----a--|');
const e1subs = '^ !';
const expected = '-----a--(yz|)';
expectObservable(e1.pipe(endWith('y', 'z', rxTestScheduler))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例3: asDiagram
asDiagram('endWith(s)')('should append to a cold Observable', () => {
const e1 = cold('---a--b--c--|');
const e1subs = '^ !';
const expected = '---a--b--c--(s|)';
expectObservable(e1.pipe(endWith('s'))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});