如何组合算子RXJS?

1 rxjs angular

我有以下四位听众:

    this.reportPropertiesChanges$.pipe(filter(() => this.loaded)).subscribe((v) => {
        this.registryReportSettings.reportProperties = v;
        this.registryReportSettings$.next(this.registryReportSettings);
    });

    this.objectsProperties$.pipe(filter(() => this.loaded)).subscribe((v) => {
        this.registryReportSettings.reportObjectsProperties = v;
        this.registryReportSettings$.next(this.registryReportSettings);
    });

    this.textPropertiesChanges$.pipe(filter(() => this.loaded)).subscribe((v) => {
        this.registryReportSettings.textProperties = v;
        this.registryReportSettings$.next(this.registryReportSettings);
    });

    this.toggleLabels$.pipe(filter(() => this.loaded)).subscribe((v) => {
        this.registryReportSettings.visibleText = v;
        this.registryReportSettings$.next(this.registryReportSettings);
    });
Run Code Online (Sandbox Code Playgroud)

如何将它们组合到一个运算符中?我无法使用combineLatest,因为并非所有流都可以启动。

yur*_*zui 6

我会将其重构为:

import { merge } from 'rxjs';
import { map } from 'rxjs/operators';
...

const forwardProp = prop => value => ({prop, value});

const obs = [
    this.reportPropertiesChanges$.pipe(map(forwardProp('reportProperties'))),
    this.objectsProperties$.pipe(map(forwardProp('reportObjectsProperties'))),
    this.textPropertiesChanges$.pipe(map(forwardProp('textProperties'))),
    this.toggleLabels$.pipe(map(forwardProp('visibleText')))
];

merge(...obs).pipe(filter(() => this.loaded)).subscribe(({prop, value}) => {
  this.registryReportSettings[prop] = value;
  this.registryReportSettings$.next(this.registryReportSettings);
});
Run Code Online (Sandbox Code Playgroud)