flippingengineer
flippingengineer

Reputation: 283

RXJS BehaviorSubject getValue vs value

I was wondering what the main difference is between the getValue function and the readonly value property on the BehaviorSubject? Is there a benefit of using one over the the other?

Upvotes: 27

Views: 9661

Answers (1)

Reactgular
Reactgular

Reputation: 54741

There is no difference between the two methods.

Internally the BehaviorSubject returns the value from getValue(). So if you are super picky about performance, then calling getValue() saves you one function call.

  get value(): T {
    return this.getValue();
  }

https://github.com/ReactiveX/rxjs/blob/1d29fe8b903c0dbc2b74a5e68abb9270e3f45015/src/internal/BehaviorSubject.ts#L19

Upvotes: 42

Related Questions