Data Stream from RxJS Observables by Reference or Value?

Viewed 172

Hello beautiful community. I have working in web apps with the most common kind of data: streams, array, objects and array of objects. When I emit this data:

    const behaviorSubject = new BehaviorSubject(null);
    somedata: SomeClass[];
    somedata: = [{prop1: 1, prop2:"string", prop3:true}, {prop1: 2, 
    prop2:"string2", prop3:false}]
    behaviorSubject.next(somedata);

And receive that data

// Another js file
receiver: SomeClass[];
objectService.observerFromBehaviorSubject().subscribe(resp => this.receiver = resp);

The received data within 'resp' from arrow function is an array of objects, so the question is: the local array "receiver" has the value of the stream by reference or it is the same as a raw data (think primitive data types: number, string, boolean which those values you can copy in simple ways) (By Value)?

1 Answers

Well after some researchs I found out that RxJS Streams are send by reference according to the following reasons:

1.- JavaScript engines are written in C++ and this post helps to understand better. Another reason to support this point is the explanation of Observables by the autor of RxJS library.

2.- Regards the theory I have a stackblitz to verify the answer.

Related