import { BehaviorSubject , Observable } from 'rxjs' ; import { distinctUntilChanged } from 'rxjs/operators' ; import { Annotation } from '../../../common/types/annotations' ; export type AnnotationState = Annotation | null ; export const annotation$ = new BehaviorSubject < AnnotationState > ( null ) ; export const annotationsRefresh$ = new BehaviorSubject ( Date . now ( ) ) ; export const annotationsRefreshed = ( ) => annotationsRefresh$ . next ( Date . now ( ) ) ; export class AnnotationUpdatesService { private _annotation$ : BehaviorSubject < AnnotationState > = new BehaviorSubject < AnnotationState > ( null ) ; public update$ ( ) { return this . _annotation$ . asObservable ( ) ; } public isAnnotationInitialized$ ( ) { return this . _annotation$ . asObservable ( ) . pipe ( distinctUntilChanged ( ( prev , curr ) => { return prev !== null && curr !== null ; } ) ) ; } public setValue ( annotation ) { this . _annotation$ . next ( annotation ) ; } }