-
Notifications
You must be signed in to change notification settings - Fork 2
/
search.actions.ts
124 lines (106 loc) · 2.71 KB
/
search.actions.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { ActionNameFactory } from '../classes/action-name-factory';
import { PayloadAction } from '../classes/payload-action';
/**
* Interface for search action names
*/
export interface SearchActionNames {
/**
* Defining the type of the `SEARCH` action type
*/
SEARCH: string;
/**
* Defining the type of the `SEARCH_COMPLETE` action type
*/
SEARCH_COMPLETE: string;
/**
* Defining the type of the `LOAD` action type
*/
LOAD: string;
/**
* Defining the type of the `SELECT` action type
*/
SELECT: string;
}
/**
* Interface for `createSearchActions` return type
*/
export interface SearchActions<T> extends SearchActionNames {
/**
* Type of the `Search` action
*/
Search: new (payload?: any) => PayloadAction<any>;
/**
* Type of the `SearchComplete` action
*/
SearchComplete: new (payload: T[]) => PayloadAction<T[]>;
/**
* Type of the `Load` action
*/
Load: new (payload: T) => PayloadAction<T>;
/**
* Type of the `Select` action
*/
Select: new (payload: string) => PayloadAction<string>;
}
/**
* Action name constants
*/
export const SearchActionNames: SearchActionNames = {
/**
* Value of the `SEARCH` action type
*/
SEARCH: 'Search',
/**
* Value of the `SEARCH_COMPLETE` action type
*/
SEARCH_COMPLETE: 'Search Complete',
/**
* Value of the `LOAD` action type
*/
LOAD: 'Load',
/**
* Value of the `SELECT` action type
*/
SELECT: 'Select'
};
/**
* Action class and type factory function for "search" actions. Returns an object of
* action classes and type strings. This actions are handled by the `NormalizedEntityState`
* reducer and the effects created by the `CrudEffectsFactory`.
* @param ns The namespace to use for creating action type constants
*/
export function createSearchActions<T>(ns: string): SearchActions<T> {
const SEARCH = ActionNameFactory.getActionName(SearchActionNames.SEARCH, ns);
const SEARCH_COMPLETE = ActionNameFactory.getActionName(
SearchActionNames.SEARCH_COMPLETE,
ns
);
const LOAD = ActionNameFactory.getActionName(SearchActionNames.LOAD, ns);
const SELECT = ActionNameFactory.getActionName(SearchActionNames.SELECT, ns);
class Search implements PayloadAction<any> {
readonly type = SEARCH;
constructor(public payload: any | undefined) {}
}
class SearchComplete implements PayloadAction<T[]> {
readonly type = SEARCH_COMPLETE;
constructor(public payload: T[]) {}
}
class Load implements PayloadAction<T> {
readonly type = LOAD;
constructor(public payload: T) {}
}
class Select implements PayloadAction<string> {
readonly type = SELECT;
constructor(public payload: string) {}
}
return {
Search,
SEARCH,
SearchComplete,
SEARCH_COMPLETE,
Load,
LOAD,
Select,
SELECT
};
}