本文整理匯總了TypeScript中rxjs/operators.single函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript single函數的具體用法?TypeScript single怎麽用?TypeScript single使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了single函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should raise error from empty predicate if observable does not emit', () => {
const e1 = hot('--a--^--|');
const e1subs = '^ !';
const expected = '---#';
expectObservable(e1.pipe(single())).toBe(expected, null, new EmptyError());
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例2: single1
single1() {
// emit (1,2,3,4,5)
const source = from([1, 2, 3, 4, 5]);
// emit one item that matches predicate
const example = source.pipe(single(val => val === 4));
// output: 4
const subscribe = example.subscribe(val => console.log(val));
}
示例3: asDiagram
asDiagram('single')('should raise error from empty predicate if observable emits multiple time', () => {
const e1 = hot('--a--b--c--|');
const e1subs = '^ ! ';
const expected = '-----# ';
const errorMsg = 'Sequence contains more than one element';
expectObservable(e1.pipe(single())).toBe(expected, null, errorMsg);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});