Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
- Loading branch information
1 parent
10623db
commit 8b44b24
Showing
12 changed files
with
206 additions
and
125 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Action } from '@ngrx/store'; | ||
import { Filter } from '@app/shared/model/options.model'; | ||
|
||
export enum ActionTypes { | ||
Failed = '[Filter Component] Failed', | ||
|
||
UpdateFilter = '[Filter Component] Update Filter', | ||
UpdateFilterSuccess = '[Filter Component] Update Filter Success', | ||
} | ||
|
||
export class Failed implements Action { | ||
readonly type = ActionTypes.Failed; | ||
constructor(public error: string) {} | ||
} | ||
|
||
export class UpdateFilter implements Action { | ||
readonly type = ActionTypes.UpdateFilter; | ||
constructor(public filter: Filter) {} | ||
} | ||
|
||
export class UpdateFilterSuccess implements Action { | ||
readonly type = ActionTypes.UpdateFilterSuccess; | ||
constructor(public filter: Filter) {} | ||
} | ||
|
||
export type FilterAction = Failed | UpdateFilter | UpdateFilterSuccess; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Actions, Effect, ofType } from '@ngrx/effects'; | ||
import { of } from 'rxjs'; | ||
import { exhaustMap, map } from 'rxjs/operators'; | ||
import { ActionTypes, UpdateFilterSuccess, UpdateFilter } from './filter.actions'; | ||
import { LoggerService } from '@shared/services/logger.service'; | ||
import { Filter } from '@app/shared/model/options.model'; | ||
|
||
@Injectable() | ||
export class FilterEffects { | ||
@Effect() | ||
updateFilter$ = this.actions$.pipe( | ||
ofType(ActionTypes.UpdateFilter), | ||
map((action: UpdateFilter) => action.filter), | ||
exhaustMap(filter => { | ||
this.logger.debug('[Filter Effects:UpdateFilter] SUCCESS'); | ||
const copy = new (filter.constructor as { new () })(); | ||
Object.assign(copy, filter); | ||
return of(new UpdateFilterSuccess(copy)); | ||
}), | ||
); | ||
|
||
constructor(private actions$: Actions, private logger: LoggerService) {} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Action, createSelector, createFeatureSelector } from '@ngrx/store'; | ||
import { ActionTypes, FilterAction } from './filter.actions'; | ||
import { Filter } from '@app/shared/model/options.model'; | ||
import { State as RootState } from '@app/app.reducer'; | ||
|
||
export interface State { | ||
error: string | null; | ||
filter: Filter; | ||
} | ||
|
||
export const initialState: State = { | ||
error: null, | ||
filter: new Filter(), | ||
}; | ||
|
||
export function filterReducer(state = initialState, action: FilterAction): State { | ||
switch (action.type) { | ||
case ActionTypes.UpdateFilterSuccess: { | ||
return { | ||
...state, | ||
filter: action.filter, | ||
}; | ||
} | ||
|
||
case ActionTypes.Failed: { | ||
return { | ||
...state, | ||
error: action.error, | ||
}; | ||
} | ||
|
||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export const selectFilter = (state: RootState) => state.filter; | ||
export const getFilterSelector = createSelector( | ||
selectFilter, | ||
(state: State) => state.filter, | ||
); |
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
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
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
Oops, something went wrong.