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