import { useEffect } from 'react' ; import { Observable } from 'rxjs/internal/Observable' ; import { NextObserver } from 'rxjs/internal/types' ; let subscriptionsCount = 0 ; const isDebugMode = typeof window !== 'undefined' && /debug$/m . test ( window . location . hash ) ; const printSubscriptionsCount = isDebugMode ? ( ) => console . debug ( '%c #' , 'color: #40bbc6;' , subscriptionsCount ) : ( ) => { } ; /**
 * Internal hook that manages subscriptions.
 */ export function useRx < T > ( observable$ , observer ) { useEffect ( ( ) => { const subscription = observable$ . subscribe ( observer ) ; subscriptionsCount ++ ; printSubscriptionsCount ( ) ; return ( ) => { subscription . unsubscribe ( ) ; subscriptionsCount -- ; printSubscriptionsCount ( ) ; } ; } , [ observable$ ] ) ; } param observable$ param tag export function useRxDebug < T > ( observable$ , tag ) { useRx ( observable$ , { next ( res ) { if ( isDebugMode ) { console . debug ( '%c %s →' , 'color: #40bbc6;' , tag , res ) ; } } , error ( e ) { if ( isDebugMode ) { console . debug ( '%c %s →' , 'color: red; font-weight: bold;' , tag , e ) ; } } } ) ; }