@@ -2,9 +2,9 @@ import * as HttpTrackingActions from './http-tracking.actions';
22import * as HttpTrackingSelectors from './http-tracking.selectors' ;
33import { Action , Store } from '@ngrx/store' ;
44import { HttpTrackingEntity } from '../model/http-tracking-entity' ;
5- import { debounceTime , filter , map , take } from 'rxjs/operators' ;
5+ import { debounceTime , filter , map , switchMap , take } from 'rxjs/operators' ;
66import { Injectable } from '@angular/core' ;
7- import { forkJoin , Observable } from 'rxjs' ;
7+ import { forkJoin , Observable , timer } from 'rxjs' ;
88import { isError } from '../function/is-error' ;
99import { mapActionTypeToId } from '../function/map-action-typ-to-id' ;
1010import { TrackingAction } from '../function/http-tracking-actions.factory' ;
@@ -77,21 +77,27 @@ export class HttpTrackingFacade {
7777 }
7878
7979 public getResolved < T1 , T2 > ( action : TrackingAction < T1 , T2 > ) : Observable < HttpTrackingResult < T1 , T2 > > {
80- return this . getTracking ( action ) . pipe (
81- filter ( tracking => ! ! tracking ) ,
82- map ( tracking => ( < HttpTrackingEntity > tracking ) . httpStatus ) ,
83- filter ( httpStatus => httpStatus === LoadingState . LOADED || isError ( httpStatus ) ) ,
84- take ( 1 ) ,
85- map ( httpStatus => {
86- const retVal = < HttpTrackingResult < T1 , T2 > > {
87- action,
88- success : httpStatus === LoadingState . LOADED ,
89- } ;
90- if ( isError ( httpStatus ) ) {
91- retVal . error = httpStatus ;
92- }
93- return retVal ;
94- } )
80+ // this timer is here to prevent an issue with retrieving the state before
81+ // the reducer is updated on a second call to the same tracked action
82+ return timer ( 1 ) . pipe (
83+ switchMap ( ( ) =>
84+ this . getTracking ( action ) . pipe (
85+ filter ( tracking => ! ! tracking ) ,
86+ map ( tracking => ( < HttpTrackingEntity > tracking ) . httpStatus ) ,
87+ filter ( httpStatus => httpStatus === LoadingState . LOADED || isError ( httpStatus ) ) ,
88+ take ( 1 ) ,
89+ map ( httpStatus => {
90+ const retVal = < HttpTrackingResult < T1 , T2 > > {
91+ action,
92+ success : httpStatus === LoadingState . LOADED ,
93+ } ;
94+ if ( isError ( httpStatus ) ) {
95+ retVal . error = httpStatus ;
96+ }
97+ return retVal ;
98+ } )
99+ )
100+ )
95101 ) ;
96102 }
97103
0 commit comments