本文整理汇总了TypeScript中rxjs.ReplaySubject.subscribe方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ReplaySubject.subscribe方法的具体用法?TypeScript ReplaySubject.subscribe怎么用?TypeScript ReplaySubject.subscribe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs.ReplaySubject
的用法示例。
在下文中一共展示了ReplaySubject.subscribe方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: inject
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const responses: Response[] = [sampleResponse1, sampleResponse2];
backend.connections.subscribe((c: MockConnection) => c.mockRespond(responses.shift() !));
const responseObservable: ReplaySubject<Response> =
backend.createConnection(sampleRequest1).response;
responseObservable.subscribe(res => expect(res.text()).toBe('response1'));
responseObservable.subscribe(
res => expect(res.text()).toBe('response2'), null !, async.done);
}));
示例2:
.then(() => {
this.candidates.subscribe((ic) =>
this.pc
.addIceCandidate(ic)
.catch((err) => log.webrtc(`${this.id}: Failed to add REMOTE Ice Candidate`, err))
)
})
示例3: replaySubject
replaySubject() {
let replaySubject$ = new ReplaySubject(2); // Buffer 2 values for new subscribers
interval(300).pipe(
take(5)
).subscribe(replaySubject$);
replaySubject$.subscribe(val => console.log(`Replay subject 1: ${val}`)); // 0, 1, 2, 3, 4
setTimeout(() => {
replaySubject$.subscribe(val => console.log(`Replay subject 2: ${val}`)); // 1, 2, 3, 4
}, 1000);
}
示例4: shareReplay3
shareReplay3() {
// simulate url change with subject
const routeEnd = new Subject<{data: any, url: string}>();
// instead of using shareReplay, use ReplaySubject
const shareWithReplay = new ReplaySubject();
// grab url and share with subscribers
const lastUrl = routeEnd.pipe(
pluck('url')
)
.subscribe(val => shareWithReplay.next(val));
// simulate route change
routeEnd.next({data: {}, url: 'my-path'});
// subscribe to ReplaySubject instead
// logged: 'my path'
shareWithReplay.subscribe(console.log);
}
示例5: setTimeout
setTimeout(() => subject$.subscribe((x) => console.log("First: " + x)), 3000);
示例6: setTimeout
setTimeout(() => {
replaySubject$.subscribe(val => console.log(`Replay subject 2: ${val}`)); // 1, 2, 3, 4
}, 1000);
示例7: constructor
constructor() {
this.saleReplaySubject = new ReplaySubject<Sale>(1);
this.saleReplaySubject.subscribe(sale => console.warn(sale));
}