import { Injectable } from '@angular/core' ; import { IAPOD , IUPDATE } from './apod.model' ; import { BehaviorSubject } from 'rxjs' ; import { scan } from 'rxjs/operators' ; @ Injectable ( { providedIn : 'root' } ) export class StateService { private initialState = null ; private apodSubject = new BehaviorSubject ( this . initialState ) ; apodStore$ = this . apodSubject . pipe ( scan ( ( acc , newVal ) => { return { ... acc , ... newVal } ; } , this . initialState ) ) ; constructor ( ) { } setStore ( obj ) { this . apodSubject . next ( obj ) ; } }