本文整理汇总了TypeScript中rxjs/operators.expand函数的典型用法代码示例。如果您正苦于以下问题:TypeScript expand函数的具体用法?TypeScript expand怎么用?TypeScript expand使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了expand函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: expand1
expand1() {
// emit 2
const source = of(2);
const example = source.pipe(
// recursively call supplied function
expand(val => {
// 2,3,4,5,6
console.log(`Passed value: ${val}`);
// 3,4,5,6
return of(1 + val);
}),
// call 5 times
take(5)
);
/*
"RESULT: 2"
"Passed value: 2"
"RESULT: 3"
"Passed value: 3"
"RESULT: 4"
"Passed value: 4"
"RESULT: 5"
"Passed value: 5"
"RESULT: 6"
"Passed value: 6"
*/
// output: 2,3,4,5,6
const subscribe = example.subscribe(val => console.log(`RESULT: ${val}`));
}
示例2: higherOrder
export function expand<T, R>(this: Observable<T>, project: (value: T, index: number) => ObservableInput<R>,
concurrent: number = Number.POSITIVE_INFINITY,
scheduler: SchedulerLike = undefined): Observable<R> {
concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
return higherOrder(project, concurrent, scheduler)(this);
}
示例3: expand
observable1 = expandZone1.run(() => {
return observable1.pipe(
expand((val: any) => {
expect(Zone.current.name).toEqual(expandZone1.name);
return of(1 + val);
}),
take(2));
});
示例4: pollBuildProgress
private pollBuildProgress(locatorType: string, locator: string, minRevision: number): Observable<ProgressStatus> {
return this.getBuildProgress(locatorType, locator, minRevision).pipe(
expand(buildDto => {
if (buildDto != null) {
locatorType = 'id';
locator = buildDto.id;
minRevision = buildDto.revision + 1;
}
return this.getBuildProgress(locatorType, locator, minRevision);
}),
filter(buildDto => buildDto != null),
map(buildDto => buildDto as BuildDto),
takeWhileInclusive(buildDto => buildDto.state === BuildStates.Pending || buildDto.state === BuildStates.Active)
);
}
示例5: it
it('should infer correctly with a different type as the source', () => {
const o = of(1, 2, 3).pipe(expand(value => of('foo'))); // $ExpectType Observable<string>
const p = of(1, 2, 3).pipe(expand(value => ['foo'])); // $ExpectType Observable<string>
const q = of(1, 2, 3).pipe(expand(value => Promise.resolve('foo'))); // $ExpectType Observable<string>
});