-
-
Save BrianJVarley/8b4f00a843aa615528af296d42d98ad5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
EAppActions, | |
GetFiles | |
} from '../actions/app.actions'; | |
import { Injectable } from '@angular/core'; | |
import { Effect, ofType, Actions } from '@ngrx/effects'; | |
import { of } from 'rxjs'; | |
import { switchMap, map, catchError, mergeMap, delay, takeWhile } from 'rxjs/operators'; | |
import { FileService } from 'src/app/utils/FileService'; | |
@Injectable() | |
export class ResourceEffects { | |
constructor( | |
private actions$: Actions, | |
private fileService: FileService, | |
) {} | |
private isPollingActive = false; | |
@Effect({ dispatch: false }) | |
continuePolling$ = this.actions$.pipe( | |
ofType<GetFiles>(EAppActions.GetFiles), | |
takeWhile(() => this.isPollingActive), | |
switchMap(() => { | |
this.isPollingActive = true; | |
return this.fileService | |
.getResourceFileJs(`http://localhost:5002/myRemoteFile.js`) | |
.pipe( | |
delay(5000), | |
map((response: any) => { | |
const responseHeaders = response.headers; | |
}), | |
); | |
}), | |
); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment