本文整理汇总了TypeScript中rxjs.Subject.pipe方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Subject.pipe方法的具体用法?TypeScript Subject.pipe怎么用?TypeScript Subject.pipe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs.Subject
的用法示例。
在下文中一共展示了Subject.pipe方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should convert observable obeject to ordinal object', done => {
const aValue = new Subject();
const bValue = new Subject();
const BUFFER_COUNT = 4;
const values = createObject(
aValue.pipe(startWith('')),
bValue.pipe(startWith('')),
);
subscription.add(
combineTemplate(values)
.pipe(bufferCount(BUFFER_COUNT))
.subscribe(v => {
/*tslint:disable:no-magic-numbers*/
expect(v[0]).to.be.deep.eq(createObject('', ''));
expect(v[1]).to.be.deep.eq(createObject('200', ''));
expect(v[2]).to.be.deep.eq(createObject('200', '300'));
expect(v[3]).to.be.deep.eq(createObject('OK', '300'));
/*tslint:enable:no-magic-numbers*/
done();
}),
);
aValue.next('200');
bValue.next('300');
aValue.next('OK');
});
示例2: useEffect
useEffect(() => {
const subject$ = new Subject<Actor<any>>();
const actorSubscription = actor$.subscribe(subject$);
const end = (cb: () => void) => {
cb();
(optionsRef.current.onFinish || noop)(dispatch);
requesting$.next(false);
};
const subscription = observableMerge(
subject$.pipe(
rxFilter(requestActor.done.is),
rxFilter((actor) => isEqual(actor.opts.parentActor.arg, lastArg.current)),
rxTap((actor: typeof requestActor.done) => {
end(() => (optionsRef.current.onSuccess || noop)(actor, dispatch));
}),
),
subject$.pipe(
rxFilter(requestActor.failed.is),
rxFilter((actor) => isEqual(actor.opts.parentActor.arg, lastArg.current)),
rxTap((actor: typeof requestActor.failed) => {
end(() => (optionsRef.current.onFail || noop)(actor, dispatch));
}),
),
).subscribe();
return () => {
subscription.unsubscribe();
actorSubscription.unsubscribe();
};
}, [requestActor]);
示例3: ngOnInit
ngOnInit() {
this.time$ = this.store.select("tickReducer");
this.hourBackward$ = new Subject();
this.hourForward$ = new Subject();
this.dayBackward$ = new Subject();
this.dayForward$ = new Subject();
this.merged$ = merge(
this.hourBackward$.pipe(mapTo({type: HOUR_TICK, payload: -1})),
this.hourForward$.pipe(mapTo({type: HOUR_TICK, payload: 1})),
this.dayBackward$.pipe(mapTo({type: DAY_TICK, payload: -1})),
this.dayForward$.pipe(mapTo({type: DAY_TICK, payload: 1})),
interval(1000).pipe(mapTo({type: SECOND_TICK, payload: 1}))
);
}
示例4: it
it('should multicast a ConnectableObservable', (done) => {
const expected = [1, 2, 3, 4];
const source = new Subject<number>();
const connectable = source.pipe(multicast(new Subject<number>())) as ConnectableObservable<number>;
const replayed = connectable.pipe(multicast(new ReplaySubject<number>())) as ConnectableObservable<number>;
connectable.connect();
replayed.connect();
source.next(1);
source.next(2);
source.next(3);
source.next(4);
source.complete();
replayed.pipe(
tap({
next(x) {
expect(x).to.equal(expected.shift());
},
complete() {
expect(expected.length).to.equal(0);
}
})
).subscribe(null, done, done);
});
示例5: return
return Observable.create(obs => {
const subscription = intersectionSubject.pipe(filter(entry => entry.target === attributes.element)).subscribe(obs);
return () => {
subscription.unsubscribe();
observer.unobserve(attributes.element);
};
});
示例6: fn
export default function createMutationBehaviorSubject<T>(
value: T
): [Subject<(state: T) => T>, BehaviorSubject<T>] {
const source = new BehaviorSubject<T>(value);
const sink = new Subject<(state: T) => T>();
sink.pipe(map(fn => fn(source.value))).subscribe(source);
return [sink, source];
}
示例7: ngOnInit
ngOnInit() {
const recallSubject$ = new Subject();
this.time$ = this.store.select("clockReducer");
this.people$ = this.store.select("peoplezReducer");
this.person$ = new Subject();
this.seconds$ = interval(1000);
this.recall$ = recallSubject$
.pipe(withLatestFrom(this.time$, (_, y) => y))
.pipe(map(time => ({type: RECALL, payload: time})));
this.merged$ = merge(
this.seconds$.pipe(mapTo({type: SECOND, payload: 1})),
this.person$.pipe(map(value => ({payload: value, type: ADVANCE}))),
this.recall$
);
}
示例8: test
test('proxy route responds with `503` if `kbnServer` is not ready yet.', async () => {
configService.atPath.mockReturnValue(new BehaviorSubject({ autoListen: true }));
const legacyService = new LegacyService({ env, logger, configService: configService as any });
const kbnServerListen$ = new Subject();
MockKbnServer.prototype.listen = jest.fn(() => {
kbnServerListen$.next();
return kbnServerListen$.toPromise();
});
// Wait until listen is called and proxy route is registered, but don't allow
// listen to complete and make kbnServer available.
await legacyService.setup(setupDeps);
const legacySetupPromise = legacyService.start(startDeps);
await kbnServerListen$.pipe(first()).toPromise();
const mockResponse: any = {
code: jest.fn().mockImplementation(() => mockResponse),
header: jest.fn().mockImplementation(() => mockResponse),
};
const mockResponseToolkit = {
response: jest.fn().mockReturnValue(mockResponse),
abandon: Symbol('abandon'),
};
const mockRequest = { raw: { req: { a: 1 }, res: { b: 2 } } };
const [[{ handler }]] = setupDeps.http.server.route.mock.calls;
const response503 = await handler(mockRequest, mockResponseToolkit);
expect(response503).toBe(mockResponse);
expect({
body: mockResponseToolkit.response.mock.calls,
code: mockResponse.code.mock.calls,
header: mockResponse.header.mock.calls,
}).toMatchSnapshot('503 response');
// Make sure request hasn't been passed to the legacy platform.
const [mockedLegacyPlatformProxy] = MockLegacyPlatformProxy.mock.instances;
expect(mockedLegacyPlatformProxy.emit).not.toHaveBeenCalled();
// Now wait until kibana is ready and try to request once again.
kbnServerListen$.complete();
await legacySetupPromise;
mockResponseToolkit.response.mockClear();
const responseProxy = await handler(mockRequest, mockResponseToolkit);
expect(responseProxy).toBe(mockResponseToolkit.abandon);
expect(mockResponseToolkit.response).not.toHaveBeenCalled();
// Make sure request has been passed to the legacy platform.
expect(mockedLegacyPlatformProxy.emit).toHaveBeenCalledTimes(1);
expect(mockedLegacyPlatformProxy.emit).toHaveBeenCalledWith(
'request',
mockRequest.raw.req,
mockRequest.raw.res
);
});
示例9: ngOnInit
ngOnInit() {
this.time$ = this.store.select("clockReducer");
this.updateHours$ = new Subject();
this.seconds$ = interval(1000).pipe(mapTo({type: SECOND, payload: 1}));
this.merged$ = merge(
this.updateHours$.pipe(map(value => ({type: HOUR, payload: value}))),
this.seconds$
);
}
示例10: constructor
/**
*
* @param period milliseconds
*/
constructor(
period?: number, // milliseconds
) {
super(period);
this.subject = new Subject<T>();
this.subscription = this.subject.pipe(
throttle(_ => interval(this.period)),
).subscribe((item: T) => super.next(item));
}