blob: c8350d893a8ba1a6be5be59ff66e1bb8546350ee [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import {Injectable} from "@angular/core";
import {Actions, createEffect, ofType} from "@ngrx/effects";
import {Action} from "@ngrx/store";
import {Observable} from "rxjs";
import {map, retry, switchMap} from "rxjs/operators";
import {SettingsApiService} from "../../../core";
import {retryAfter} from "../../../util";
import {intializeAction} from "../../root/actions";
import {setStatementTypesAction} from "../actions";
@Injectable({providedIn: "root"})
export class StatementTypesEffects {
public initialize$ = createEffect(() => this.actions.pipe(
ofType(intializeAction),
switchMap(() => {
return this.fetchStatementTypes().pipe(
retryAfter(30000)
);
})
));
public constructor(private readonly actions: Actions, private readonly settingsApiService: SettingsApiService) {
}
public fetchStatementTypes(): Observable<Action> {
return this.settingsApiService.getStatementTypes().pipe(
map((statementTypes) => setStatementTypesAction({statementTypes})),
retry(2)
);
}
}