import { Injectable } from '@angular/core'; import { TargetingFormActions } from './targeting-form.actions'; import { TARGETING_FORM_KEY, TargetingFormState } from './targeting-form.reducer'; import { AppState } from '../../../../app/reducers/index'; import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; import { distinctUntilChanged, map } from 'rxjs/operators'; import { TARGETING_KEY, TargetingState } from '../targeting.reducer'; @Injectable() export class TargetingFormService { static getModel (_store): Observable { return _store.select(TARGETING_KEY) .pipe( map((targeting: TargetingState) => targeting[TARGETING_FORM_KEY]), distinctUntilChanged() ); } setFormValue (formValue: TargetingFormState) { this._store.dispatch(this.targetingFormActions.setFormValue(formValue)); } constructor (private _store: Store, private targetingFormActions: TargetingFormActions) {} }