0

I have two subjects: networkStateSubject and authStateSubject.

networkStateSubject emits boolean value:

    true if network connectivity is enabled,

    false if network connectivity is disabled.

authStateSubject emits boolean value:

    true if user logged in,

    false if user logged out.

I need to combine these two subjects, so that whenever both of their values are true, new value (void) is emitted from combined observable.

Ziyaddin Sadigov
  • 8,893
  • 13
  • 34
  • 41

2 Answers2

2

You can use combineLatest and filter to check for both values.

const connectedAndAuth$ = combineLatest([networkStateSubject, authStateSubject])
   .pipe(
      filter(([isConnected, isAuth]) => isConnected && isAuth),
      map(_ => 1) //what do you mean emit a void value?
   );
Andrei Tătar
  • 7,872
  • 19
  • 37
1

I would use combineLatest with a selector networkStateSubject && authStateSubject, and then filter the true ones

Krzysztof Skowronek
  • 2,796
  • 1
  • 13
  • 29