• expand
    • 签名: expand(project: function, concurrent: number, scheduler: Scheduler): Observable
  • 递归调用提供的函数
    • 示例
      • 示例 1: 每次调用加1
  • 相关食谱
  • 其他资源

    expand

    签名: expand(project: function, concurrent: number, scheduler: Scheduler): Observable

    递归调用提供的函数

    expand - 图1

    示例

    示例 1: 每次调用加1

    ( StackBlitz |
    jsBin |
    jsFiddle )

    1. import { interval } from 'rxjs/observable/interval';
    2. import { of } from 'rxjs/observable/of';
    3. import { expand, take } from 'rxjs/operators';
    4. // 发出 2
    5. const source = of(2);
    6. const example = source.pipe(
    7. // 递归调用提供的函数
    8. expand(val => {
    9. // 2,3,4,5,6
    10. console.log(`Passed value: ${val}`);
    11. // 3,4,5,6
    12. return of(1 + val);
    13. }),
    14. // 用5次
    15. take(5)
    16. );
    17. /*
    18. "RESULT: 2"
    19. "Passed value: 2"
    20. "RESULT: 3"
    21. "Passed value: 3"
    22. "RESULT: 4"
    23. "Passed value: 4"
    24. "RESULT: 5"
    25. "Passed value: 5"
    26. "RESULT: 6"
    27. "Passed value: 6"
    28. */
    29. // 输出: 2,3,4,5,6
    30. const subscribe = example.subscribe(val => console.log(`RESULT: ${val}`));

    相关食谱

    • 游戏循环

    其他资源

    • expand :newspaper: - 官方文档

    :file_folder: 源码: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/expand.ts