Skip to content

Commit a275126

Browse files
committed
Replaces spinner state with a third-party package
1 parent c986783 commit a275126

File tree

6 files changed

+8
-63
lines changed

6 files changed

+8
-63
lines changed

Diff for: src/app/core/actions/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as MessageApiActions from './message.actions';
2-
import * as SpinnerActions from './spinner.actions';
32
import * as UserActions from './user.actions';
43

5-
export { MessageApiActions, SpinnerActions, UserActions };
4+
export { MessageApiActions, UserActions };

Diff for: src/app/core/actions/spinner.actions.ts

-4
This file was deleted.

Diff for: src/app/core/interceptors/loading.interceptor.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
HttpRequest,
66
} from '@angular/common/http';
77
import { Injectable } from '@angular/core';
8-
import { IsLoadingService } from '@service-work/is-loading';
98
import { Observable } from 'rxjs';
109
import { finalize } from 'rxjs/operators';
1110
import { SpinnerFacadeService } from '../services/spinner-facade.service';
@@ -14,18 +13,14 @@ import { SpinnerFacadeService } from '../services/spinner-facade.service';
1413
export class LoadingInterceptor implements HttpInterceptor {
1514
activeRequests = 0;
1615

17-
constructor(
18-
private loadingService: IsLoadingService,
19-
private spinnerFacade: SpinnerFacadeService
20-
) {}
16+
constructor(private spinnerFacade: SpinnerFacadeService) {}
2117

2218
intercept(
2319
request: HttpRequest<any>,
2420
next: HttpHandler
2521
): Observable<HttpEvent<any>> {
2622
if (this.activeRequests === 0) {
2723
this.spinnerFacade.show();
28-
this.loadingService.add({ key: 'loading' });
2924
}
3025

3126
this.activeRequests++;
@@ -36,7 +31,6 @@ export class LoadingInterceptor implements HttpInterceptor {
3631

3732
if (this.activeRequests === 0) {
3833
this.spinnerFacade.hide();
39-
this.loadingService.remove({ key: 'loading' });
4034
}
4135
})
4236
);

Diff for: src/app/core/reducers/spinner.reducers.ts

-25
This file was deleted.

Diff for: src/app/core/services/spinner-facade.service.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import { Injectable } from '@angular/core';
2-
import { select, Store } from '@ngrx/store';
2+
import { IsLoadingService } from '@service-work/is-loading';
33
import { Observable } from 'rxjs';
4-
import * as fromRoot from '../../reducers';
5-
import { SpinnerActions } from '../actions';
64

75
@Injectable()
86
export class SpinnerFacadeService {
7+
private key = 'loading';
98
showSpinner$: Observable<boolean>;
109

11-
constructor(private store: Store<fromRoot.State>) {
12-
this.showSpinner$ = this.store.pipe(select(fromRoot.selectShowSpinner));
10+
constructor(private isLoadingService: IsLoadingService) {
11+
this.showSpinner$ = this.isLoadingService.isLoading$({ key: this.key });
1312
}
1413

1514
hide(): void {
16-
this.store.dispatch(SpinnerActions.hideSpinner());
15+
this.isLoadingService.remove({ key: this.key });
1716
}
1817

1918
show(): void {
20-
this.store.dispatch(SpinnerActions.showSpinner());
19+
this.isLoadingService.add({ key: this.key });
2120
}
2221
}

Diff for: src/app/reducers/index.ts

-18
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,19 @@ import {
44
Action,
55
ActionReducer,
66
ActionReducerMap,
7-
createFeatureSelector,
8-
createSelector,
97
MetaReducer,
108
} from '@ngrx/store';
119
import { environment } from '../../environments/environment';
1210
import { AuthActions } from '../auth/actions';
13-
import * as fromSpinner from '../core/reducers/spinner.reducers';
1411

1512
export interface State {
16-
[fromSpinner.spinnerFeatureKey]: fromSpinner.State;
1713
router: fromRouter.RouterReducerState<any>;
1814
}
1915

2016
export const ROOT_REDUCERS = new InjectionToken<
2117
ActionReducerMap<State, Action>
2218
>('Root reducers token', {
2319
factory: () => ({
24-
[fromSpinner.spinnerFeatureKey]: fromSpinner.reducer,
2520
router: fromRouter.routerReducer,
2621
}),
2722
});
@@ -56,16 +51,3 @@ export function clearState(
5651
export const metaReducers: MetaReducer<State>[] = !environment.production
5752
? [clearState, logger]
5853
: [clearState];
59-
60-
/**
61-
* Spinner Reducers
62-
*/
63-
export const selectSpinnerState = createFeatureSelector<
64-
State,
65-
fromSpinner.State
66-
>(fromSpinner.spinnerFeatureKey);
67-
68-
export const selectShowSpinner = createSelector(
69-
selectSpinnerState,
70-
fromSpinner.getShowSpinner
71-
);

0 commit comments

Comments
 (0)