本文整理匯總了TypeScript中rxjs.EMPTY類的典型用法代碼示例。如果您正苦於以下問題:TypeScript EMPTY類的具體用法?TypeScript EMPTY怎麽用?TypeScript EMPTY使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了EMPTY類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: empty1
empty1() {
// output: 'Complete!'
const subscribe = EMPTY.subscribe({
next: () => console.log('Next'),
complete: () => console.log('Complete!')
});
}
示例2: it
it('should throw EmptyError if empty', () => {
let thrown: any;
EMPTY.pipe(
throwIfEmpty(),
)
.subscribe({
error(err) {
thrown = err;
}
});
expect(thrown).to.be.instanceof(EmptyError);
});
示例3: defaultIfEmpty2
defaultIfEmpty2() {
// emit 'Observable.empty()!' when empty, else any values from source
const example = EMPTY.pipe(defaultIfEmpty('Observable.empty()!'));
// output: 'Observable.empty()!'
const subscribe = example.subscribe(val => console.log(val));
}
示例4: it
it('should convert an empty Observable to a promise of undefined', (done: MochaDone) => {
EMPTY.toPromise(Promise).then((x) => {
expect(x).to.be.undefined;
done();
});
});