Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

264
Visualizações
¿Cómo combinar operadores RXJS?

Tengo los siguientes cuatro oyentes:

 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); });

¿Cómo combinarlos en un solo operador? No puedo usar combineLatest porque no se pueden iniciar todas las transmisiones.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Lo refactorizaría a algo como:

 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); });
over 4 years ago · Santiago Trujillo Relatório

0

Puede usar merge , que se activará si algún Observable emite un valor

 this.reportPropertiesChanges$.pipe(map(reportProperties => ({reportProperties}))); this.objectsProperties$.pipe(map(reportObjectsProperties => ({reportObjectsProperties}))); this.textPropertiesChanges$.pipe(map(textProperties => ({textProperties}))) this.toggleLabels$.pipe(map(visibleText => ({visibleText}))); merge( this.reportPropertiesChanges$, this.objectsProperties$, this.textPropertiesChanges$, this.toggleLabels$ ) .pipe( filter(() => this.loaded) ).subscribe((p) => { this.registryReportSettings = {...this.registryReportSettings, ...p }; this.registryReportSettings$.next(this.registryReportSettings); });
over 4 years ago · Santiago Trujillo Relatório

0

También puede usar el operador combineLatest de rxjs. Le dará acceso a los 4 suscriptibles en un solo operador. Algo como esto:

 const reportProps = this.reportPropertiesChanges$; const objectsProperties = this. objectsProperties$; const textPropertiesChanges = this.textPropertiesChanges$; const toggleLabels = this. toggleLabels$; combineLatest([ reportProps, objectsProperties, textPropertiesChanges, toggleLabels ]).pipe(filter(() => this.loaded)).subscribe(([ reportPropsValue, objPropsValue, textChangesValue, toggleLabelsValue ]) => { this.registryReportSettings.reportProperties = reportPropsValue; this.registryReportSettings.reportObjectsProperties = objPropsValue; this.registryReportSettings.textProperties = textChangesValue; this.registryReportSettings.visibleText = toggleLabelsValue; // Once you set all the values, you can update the Behavior Subject this.registryReportSettings$.next(this.registryReportSettings); })
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda