-
Notifications
You must be signed in to change notification settings - Fork 2
/
create.actions.ts
104 lines (90 loc) · 2.34 KB
/
create.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
import { ActionNameFactory } from '../classes/action-name-factory';
import { PayloadAction } from '../classes/payload-action';
/**
* Interface for create action names
*/
export interface EntityCreateActionNames {
/**
* Defining the type of the `CREATE` action type
*/
CREATE: string;
/**
* Defining the type of the `CREATE_SUCCESS` action type
*/
CREATE_SUCCESS: string;
/**
* Defining the type of the `CREATE_FAIL` action type
*/
CREATE_FAIL: string;
}
/**
* Interface for `createCreateActions` return type
*/
export interface CreateActions<T> extends EntityCreateActionNames {
/**
* Type of the `Create` action
*/
Create: new (payload: T) => PayloadAction<T>;
/**
* Type of the `CreateSuccess` action
*/
CreateSuccess: new (payload: T) => PayloadAction<T>;
/**
* Type of the `CreateFail` action
*/
CreateFail: new (payload?: any) => PayloadAction<any>;
}
/**
* Action name constants
*/
export const CreateActionNames: EntityCreateActionNames = {
/**
* Value of the `CREATE` action type
*/
CREATE: 'Create',
/**
* Value of the `CREATE_SUCCESS` action type
*/
CREATE_SUCCESS: 'Create Success',
/**
* Value of the `CREATE_FAIL` action type
*/
CREATE_FAIL: 'Create Fail'
};
/**
* Action class and type factory function for "create" 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 createCreateActions<T>(ns: string): CreateActions<T> {
const CREATE = ActionNameFactory.getActionName(CreateActionNames.CREATE, ns);
const CREATE_SUCCESS = ActionNameFactory.getActionName(
CreateActionNames.CREATE_SUCCESS,
ns
);
const CREATE_FAIL = ActionNameFactory.getActionName(
CreateActionNames.CREATE_FAIL,
ns
);
class Create implements PayloadAction<T> {
readonly type = CREATE;
constructor(public payload: T) {}
}
class CreateSuccess implements PayloadAction<T> {
readonly type = CREATE_SUCCESS;
constructor(public payload: T) {}
}
class CreateFail implements PayloadAction<any> {
readonly type = CREATE_SUCCESS;
constructor(public payload: any | undefined) {}
}
return {
Create,
CREATE,
CreateSuccess,
CREATE_SUCCESS,
CreateFail,
CREATE_FAIL
};
}