-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathpublished-data.reducer.ts
69 lines (61 loc) · 1.68 KB
/
published-data.reducer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { createReducer, Action, on } from "@ngrx/store";
import {
initialPublishedDataState,
PublishedDataState,
} from "state-management/state/published-data.store";
import * as fromActions from "state-management/actions/published-data.actions";
const reducer = createReducer(
initialPublishedDataState,
on(
fromActions.fetchAllPublishedDataCompleteAction,
(state, { publishedData }): PublishedDataState => ({
...state,
publishedData,
}),
),
on(
fromActions.fetchCountCompleteAction,
(state, { count }): PublishedDataState => ({
...state,
totalCount: count,
}),
),
on(
fromActions.fetchPublishedDataCompleteAction,
(state, { publishedData }): PublishedDataState => ({
...state,
currentPublishedData: publishedData,
}),
),
on(
fromActions.changePageAction,
(state, { page, limit }): PublishedDataState => {
const skip = page * limit;
const filters = { ...state.filters, skip, limit };
return { ...state, filters };
},
),
on(
fromActions.sortByColumnAction,
(state, { column, direction }): PublishedDataState => {
const sortField = column + (direction ? ":" + direction : "");
const filters = { ...state.filters, sortField, skip: 0 };
return { ...state, filters };
},
),
on(
fromActions.clearPublishedDataStateAction,
(): PublishedDataState => ({
...initialPublishedDataState,
}),
),
);
export const publishedDataReducer = (
state: PublishedDataState | undefined,
action: Action,
) => {
if (action.type.indexOf("[PublishedData]") !== -1) {
console.log("Action came in! " + action.type);
}
return reducer(state, action);
};