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