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

106
Visualizações
expected behavior of immutability in rxjs observables

I've been troubleshooting a pretty nasty bug where I've eventually realized that it was caused by mutation of a nested object that was passed down the stream of observables and it really surprised me since I was thinking that Observables and their payload are immutable. to understand it better I've reproduced the scenario in the following CodeSandBox (check out the console logs).

is it an expected behavior when working with rxjs observables?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

In your code both streams are referencing the same object from of(obj), that's why you observed the unexpected mutation.

To make data immutable, objDownStream1$ needs to return a copy of the obj instead.

const objDownStream1$ = intervalObj$.pipe(
  map((obj) => {
    return {...obj, nestedObj: { nestedProp: "downStream1Nested" } }
  })
);
about 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