本文整理汇总了TypeScript中rxjs.combineLatest函数的典型用法代码示例。如果您正苦于以下问题:TypeScript combineLatest函数的具体用法?TypeScript combineLatest怎么用?TypeScript combineLatest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了combineLatest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: bindTranscript
bindTranscript(records: any[]): Observable<LiftedData> {
const crosslistedRecords = combineLatest(
records.filter(record => record.quality).map(record =>
this.institution
.course(record.course)
.data()
.pipe(
map(data => [record.course, ...(data.crosslists || [])] as string[])
)
)
);
return combineLatest(
this.data().pipe(
map(function lift(program: ProgramData): LiftedData {
return {
requirements: program.requirements
? program.requirements.map(requirement => lift(requirement))
: null,
program,
progress: {} as ProgressData
} as LiftedData;
})
),
records.length == 0 ? of([]) : crosslistedRecords
).pipe(
map(([lifted, crosslistedRecords]) =>
resolve(lifted, crosslistedRecords.slice())
)
);
}
示例2: type
type('should support arrays of observables', () => {
/* tslint:disable:no-unused-variable */
let a: Observable<number>[];
let o1: Observable<number[]> = combineLatest(a);
let o2: Observable<number[]> = combineLatest(...a);
let o3: Observable<number> = combineLatest(a, (...x: any[]) => x.length);
/* tslint:enable:no-unused-variable */
});
示例3: test
test('returns data and admin client observables as a part of the contract', async () => {
const mockAdminClusterClientInstance = { close: jest.fn() };
const mockDataClusterClientInstance = { close: jest.fn() };
MockClusterClient.mockImplementationOnce(
() => mockAdminClusterClientInstance
).mockImplementationOnce(() => mockDataClusterClientInstance);
const setupContract = await elasticsearchService.setup();
const [esConfig, adminClient, dataClient] = await combineLatest(
setupContract.legacy.config$,
setupContract.adminClient$,
setupContract.dataClient$
)
.pipe(first())
.toPromise();
expect(adminClient).toBe(mockAdminClusterClientInstance);
expect(dataClient).toBe(mockDataClusterClientInstance);
expect(MockClusterClient).toHaveBeenCalledTimes(2);
expect(MockClusterClient).toHaveBeenNthCalledWith(
1,
esConfig,
expect.objectContaining({ context: ['elasticsearch', 'admin'] })
);
expect(MockClusterClient).toHaveBeenNthCalledWith(
2,
esConfig,
expect.objectContaining({ context: ['elasticsearch', 'data'] })
);
expect(mockAdminClusterClientInstance.close).not.toHaveBeenCalled();
expect(mockDataClusterClientInstance.close).not.toHaveBeenCalled();
});
示例4: applyInternal
protected applyInternal(node: Element, directive: IDirective<string>, state: INodeState) {
const observable = directive.evaluate(this.dataFlow) as Observable<string> | Observable<string>[];
let subscription;
if (Array.isArray(observable)) {
subscription = combineLatest(observable).subscribe(values => {
const zipped = directive.parameters.map((text, i) => {
let value = values[i];
if ((value === null) || (value === undefined)) {
value = "";
} else if (Array.isArray(value)) {
value = value.join(", ");
}
return text + value;
});
node.nodeValue = zipped.join("");
});
} else {
subscription = observable.subscribe(value => {
if ((value === null) || (value === undefined)) {
value = "";
} else if (Array.isArray(value)) {
value = value.join(", ");
}
node.textContent = value;
});
}
directive.cleanup.add(subscription);
}
示例5: switchMap
return switchMap(obs => {
return combineLatest(
...obs.map(o => o.pipe(take(1), startWith(INITIAL_VALUE as INTERIM_VALUES))))
.pipe(
scan(
(acc: INTERIM_VALUES, list: INTERIM_VALUES[]) => {
let isPending = false;
return list.reduce((innerAcc, val, i: number) => {
if (innerAcc !== INITIAL_VALUE) return innerAcc;
// Toggle pending flag if any values haven't been set yet
if (val === INITIAL_VALUE) isPending = true;
// Any other return values are only valid if we haven't yet hit a pending call.
// This guarantees that in the case of a guard at the bottom of the tree that
// returns a redirect, we will wait for the higher priority guard at the top to
// finish before performing the redirect.
if (!isPending) {
// Early return when we hit a `false` value as that should always cancel
// navigation
if (val === false) return val;
if (i === list.length - 1 || val instanceof UrlTree) {
return val;
}
}
return innerAcc;
}, acc);
},
INITIAL_VALUE),
filter(item => item !== INITIAL_VALUE), take(1)) as Observable<boolean|UrlTree>;
});
示例6: combineLatest1
combineLatest1() {
// timerOne emits first value at 1s, then once every 4s
const timerOne = timer(1000, 4000);
// timerTwo emits first value at 2s, then once every 4s
const timerTwo = timer(2000, 4000);
// timerThree emits first value at 3s, then once every 4s
const timerThree = timer(3000, 4000);
// when one timer emits, emit the latest values from each timer as an array
const combined = combineLatest(timerOne, timerTwo, timerThree);
const subscribe = combined.subscribe(
([timerValOne, timerValTwo, timerValThree]) => {
/*
Example:
timerOne first tick: 'Timer One Latest: 1, Timer Two Latest:0, Timer Three Latest: 0
timerTwo first tick: 'Timer One Latest: 1, Timer Two Latest:1, Timer Three Latest: 0
timerThree first tick: 'Timer One Latest: 1, Timer Two Latest:1, Timer Three Latest: 1
*/
console.log(
`Timer One Latest: ${timerValOne},
Timer Two Latest: ${timerValTwo},
Timer Three Latest: ${timerValThree}`
);
}
);
}
示例7: of
observable1 = constructorZone1.run(() => {
const source = of(1, 2, 3);
const input = of(4, 5, 6);
return combineLatest(source, input, (x: number, y: number) => {
return x + y;
});
});
示例8: switchMap
switchMap(plans => {
const planDetails = plans.map(plan => {
return fetchServicePlanDetail(parent.id, plan.name).pipe(
retry(2),
map(({ response }) => ({ name: plan.name, ...response }))
);
});
return combineLatest(...planDetails);
})
示例9: memoize
export const watchFormControl = memoize((control: FormControl) => concat(
of(control),
combineLatest(
control.statusChanges,
control.valueChanges
).pipe(
map(() => control)
)
));
示例10: it
it('should combineLatest the provided observables', () => {
const firstSource = hot('----a----b----c----|');
const secondSource = hot('--d--e--f--g--|');
const expected = '----uv--wx-y--z----|';
const combined = combineLatest(firstSource, secondSource,
(a, b) => '' + a + b);
expectObservable(combined).toBe(expected, {u: 'ad', v: 'ae', w: 'af', x: 'bf', y: 'bg', z: 'cg'});
});
示例11: ngOnInit
ngOnInit() {
this.block$ = combineLatest(
this.config.currentChain$,
this.route.paramMap.pipe(
switchMap(params => of(params.get('hash'))),
filter((hash): hash is string => typeof hash === 'string')
)
).pipe(
switchMap(([chain, hash]) => this.apiService.streamBlock(chain, hash))
);
}
示例12: googleSignIn
googleSignIn() {
combineLatest(this.auth.signIn(), this.route.queryParams, (res: boolean, param: Params) => {
return { success: res, redirectTo: param['return'] || '/' };
})
.subscribe((signInRes: { success: boolean, redirectTo: string }) => {
if (signInRes.success) {
this.router.navigateByUrl(signInRes.redirectTo);
} else {
console.error('login failed');
}
})
}
示例13: ngOnInit
ngOnInit(): void {
combineLatest(this.route.parent.url, this.route.params)
.subscribe((route) => {
const url = route[0];
const params = route[1];
if(url[1].path == 'new') {
this.create(params);
} else {
this.load(params['id']);
}
});
}
示例14: queryCosmosForUIVersions
function getUpdateAvailable$() {
const uiMetaData$ = getUiMetadata$();
const cosmosVersions$ = queryCosmosForUIVersions();
return combineLatest<[UIMetadata, Package]>([
uiMetaData$,
cosmosVersions$
]).pipe(
map(([uiMetaData, packageInfo]) =>
versionUpdateAvailable(packageInfo, uiMetaData)
)
);
}
示例15: statusChanges
get statusChanges(): Observable<any | null> {
let statusChanges = this.ngControl.statusChanges;
if (this.parentForm) {
statusChanges = combineLatest(
statusChanges,
this.parentForm.statusChanges,
);
}
return statusChanges;
}