@@ -2,9 +2,9 @@ import * as HttpTrackingActions from './http-tracking.actions';
2
2
import * as HttpTrackingSelectors from './http-tracking.selectors' ;
3
3
import { Action , Store } from '@ngrx/store' ;
4
4
import { 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' ;
6
6
import { Injectable } from '@angular/core' ;
7
- import { forkJoin , Observable } from 'rxjs' ;
7
+ import { forkJoin , Observable , timer } from 'rxjs' ;
8
8
import { isError } from '../function/is-error' ;
9
9
import { mapActionTypeToId } from '../function/map-action-typ-to-id' ;
10
10
import { TrackingAction } from '../function/http-tracking-actions.factory' ;
@@ -77,21 +77,27 @@ export class HttpTrackingFacade {
77
77
}
78
78
79
79
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
+ )
95
101
) ;
96
102
}
97
103
0 commit comments