-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
executable file
·121 lines (88 loc) · 2.83 KB
/
index.d.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
//==========================================
// Flow types
//==========================================
export declare type RequestId = string | number | symbol
export declare enum RequestStatus {
PENDING, FAILED, SUCCESS, DIRTY, CLEAN, REMOVE
}
/**
* Request state type of a single request
*/
export declare interface RequestState {
id?: RequestId;
$id: Symbol,
pending: boolean;
success: boolean;
failed: boolean;
successCount: number;
failureCount: number;
clean: boolean,
message?: any;
}
/**
* Request actions for turning request states
*/
export declare interface RequestActions {
success (id: RequestId, message?: any): any;
failed (id: RequestId, message?: any): any;
pending (id: RequestId, message?: any): any;
remove (id: RequestId, message?: any): any;
clean (id: RequestId): any;
dirty (id: RequestId): any;
}
export declare interface ProviderRequestState {
[s: string]: RequestState
}
/**
* Request object received by inject functions and props
*/
export declare interface RequestProp {
data: RequestState;
actions: RequestActions;
}
/**
* Request object received by components wrapped with `withRequest` HOC
*/
export declare interface RequestMapProp {
data: {[id: string]: RequestState };
actions: RequestActions;
}
export declare interface StateProvider {
name: string
/**
* Gets all of the request states in store
* @returns {{}}
*/
getState():any;
/**
* Updates a specific requestState in store
* @param requestStatus
* @returns {null}
*/
updateRequest (requestStatus: { id: RequestId, messsage?: any, status: RequestStatus }): void
/**
* Observe changes to the request state and re-renders the RequestProvider tree subsequently
*/
observe (updater: (shouldUpdate: boolean) => any): void
/**
* Releases all resources before unmounting RequestProvider (componentWillUnmount)
*/
release (): void
}
// ===============
// redux
// ==============
export declare interface ReduxRequestState {
id: Symbol,
data: ProviderRequestState
}
export declare function createRequestState(id: RequestId): CreateRequest;
export declare interface CreateRequest {
id: string | number,
pending: (message?: any) => { type: string, payload: { id: RequestId, status: string, message?: any }}
success: (message?: any, remove?: boolean) => { type: string, payload: { id: RequestId, status: string, message?: any }}
failed: (message?: any, remove?: boolean) => { type: string, payload: { id: RequestId, status: string, message?: any }}
remove: () => { type: string, payload: { id: RequestId, status: string }}
dirty: () => { type: string, payload: { id: RequestId, status: string }}
clean: () => { type: string, payload: { id: RequestId, status: string }}
}