I have to transform an object property in a RXJS Observable. This works using the "map" operator. The problem occurs when I subscribe twice to the same observable: the property is transformed twice
I have tried to use the "share" operator and multiple variations but nothing seems to work
Code Example:
const source = of(
{ id: 1, name: 'John' },
);
const personObservable = source.pipe(
map(person => {
person.name = person.name + '_test'; return person;
}),
);
personObservable.subscribe(
person => console.log('first: ', person)
);
personObservable.subscribe(
person => console.log('second: ', person)
);
Expected result:
first: John_test
second: John_test
Actual result:
first: John_test
second: John_test_test