11import { createReducer, on } from '@ngrx/store';
2- import * as GridListActions from 'src/app/grid-list/store/actions/grid-list.actions'
2+ import * as GridListActions from 'src/app/grid-list/store/actions/grid-list.actions';
33import { EntityState, createEntityAdapter, EntityAdapter } from '@ngrx/entity';
44import * as fromRoot from 'src/app/store/reducers';
55
@@ -10,29 +10,32 @@ export interface State extends fromRoot.State {
1010}
1111
1212export interface GridState extends EntityState<any> {
13- error: any,
14- isFecting: boolean,
13+ error: any;
14+ isFecting: boolean;
1515}
1616
17+ export const gridAdapter: EntityAdapter<any> = createEntityAdapter<any>();
1718
18- export const gridAdapter: EntityAdapter<
19- any
20- > = createEntityAdapter<any>();
21-
22- export const gridInitialState: GridState = gridAdapter.getInitialState(
23- {
24- error: null,
25- isFecting: false,
26- }
27- );
28-
19+ export const gridInitialState: GridState = gridAdapter.getInitialState({
20+ error: null,
21+ isFecting: false,
22+ });
2923
3024export const gridReducer = createReducer(
3125 gridInitialState,
26+ on(GridListActions.loadGridLists, (state) => {
27+ return { ...state, isFecting: true };
28+ }),
3229
33- on(GridListActions.loadGridLists, state => { return {...state, isFecting: true}}),
34- on(GridListActions.loadGridListsSuccess, (state, action) => gridAdapter.addMany(action.data, {...state, isFecting: false})),
35- on(GridListActions.loadGridListsFailure, (state, action) => { return {...state, error: action.error, isFecting: false}} ),
30+ on(GridListActions.loadGridListsSuccess, ( state, action) =>
31+ gridAdapter.addMany(action.data, { ...state, isFecting: false })
32+ ),
3633
37- );
34+ on(GridListActions.loadGridListsFailure, (state, action) => {
35+ return { ...state, error: action.error, isFecting: false };
36+ }),
3837
38+ on(GridListActions.UpdateListObject, (state, action) =>
39+ gridAdapter.updateOne(action.update, { ...state })
40+ )
41+ );
0 commit comments