本文整理汇总了TypeScript中rxjs/Rx.Subscriber.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Subscriber.create方法的具体用法?TypeScript Subscriber.create怎么用?TypeScript Subscriber.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Rx.Subscriber
的用法示例。
在下文中一共展示了Subscriber.create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: watchPhoto
watchPhoto(photoId: number): Observable<any> {
let openSubscriber = Subscriber.create(
() => this.webSocket.sendPhotoMessage({photoId: photoId}));
return this.webSocket.createObservableSocketWithSubscriber('ws://localhost:8000', openSubscriber)
.map(message => JSON.parse(message));
}
示例2: watchProduct
watchProduct(productId: number): Observable<any> {
let openSubscriber = Subscriber.create(
() => this.webSocket.send({productId: productId}));
return this.webSocket.createObservableSocket('ws://localhost:8000', openSubscriber)
.map(message => JSON.parse(message));
}
示例3: it
it('should observe for complete Notification', () => {
let observed = false;
const n = Notification.createComplete();
const observer = Rx.Subscriber.create((x: any) => {
throw 'should not be called';
}, (err: any) => {
throw 'should not be called';
}, () => {
observed = true;
});
n.observe(observer);
expect(observed).to.be.true;
});
示例4: it
it('should be possible to unsubscribe in the middle of the iteration', (done) => {
const expected = [10, 20, 30];
const subscriber = Rx.Subscriber.create(
(x) => {
expect(x).to.equal(expected.shift());
if (x === 30) {
subscriber.unsubscribe();
done();
}
}, (x) => {
done(new Error('should not be called'));
}, () => {
done(new Error('should not be called'));
}
);
fromIterable([10, 20, 30, 40, 50, 60], undefined).subscribe(subscriber);
});
示例5: fromIterable
'but is unsubscribed early', (done) => {
const expected = [10, 20, 30, 40];
const source = fromIterable(
[10, 20, 30, 40],
Rx.Scheduler.queue
);
const subscriber = Rx.Subscriber.create(
(x) => {
expect(x).to.equal(expected.shift());
if (x === 30) {
subscriber.unsubscribe();
done();
}
}, (x) => {
done(new Error('should not be called'));
}, () => {
done(new Error('should not be called'));
});
source.subscribe(subscriber);
});