本文整理汇总了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);
});