Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!