Types

createApis

1
/**
2
* @arg {string} path Request URL path
3
* @arg {*} payload Request payload. Omit if method is GET.
4
* @arg {object} options Axios options
5
*
6
* @returns {Promise<AxiosResponse>}
7
*/
8
interface makeRequest {
9
(path: string, ...rest: any[]): Promise<AxiosResponse>;
10
}
11
​
12
interface AxiosWrapperInstance {
13
get: makeRequest;
14
put: makeRequest;
15
patch: makeRequest;
16
post: makeRequest;
17
delete: makeRequest;
18
addAuthorization: {
19
(authorization: string): void;
20
};
21
removeAuthorization: {
22
(): void;
23
};
24
addHeader: {
25
(name: string, value: string): void;
26
};
27
removeHeader: {
28
(name: string): void;
29
};
30
instance: AxiosInstance;
31
}
32
​
33
​
34
/**
35
* @arg {string} path URL Path
36
* @arg {any} payload Request payload. Skip if GET.
37
* @arg {function} success Success action
38
* @arg {function} fail Fail action
39
* @arg {function} done? Done action
40
*/
41
interface makeCall {
42
(path: string, ...rest: any[]): Promise<AxiosResponse>;
43
}
44
​
45
interface SagaApiInstance {
46
get: makeCall;
47
post: makeCall;
48
put: makeCall;
49
patch: makeCall;
50
delete: makeCall;
51
}
52
​
53
/**
54
* @param {AxiosRequestConfig} options Axios configuration
55
*/
56
declare const createApis: (options: AxiosRequestConfig) => {
57
api: AxiosWrapperInstance;
58
sagaApi: SagaApiInstance;
59
};
Copied!

refetch

  • Fetch whatever is in state.current again in order to refresh a resource after an association or other out of context action.
1
/**
2
* @param {object} A Actions object
3
* @param {string} name Name of state scope to grab current
4
* @param {number} delay Debounce time
5
*
6
* @returns {object} An object to add to a saga slice
7
*/
8
declare const refetch: (A: any, name: string, delay: number) => SagaObject;
Copied!

crudSaga

  • Creates crud saga boilerplate clojure for sagas slice
1
interface SagaApiOpts extends Pick<ModuleOpts, 'name' | 'takers' | 'sagas'> {
2
sagaApi: any;
3
}
4
​
5
interface ExtendSagasFn {
6
(actions: any): {
7
[type: string]: SagaObject;
8
};
9
}
10
​
11
/**
12
* @arg {object} options Options to pass to saga helper
13
* @param {string} options.name REST resource name
14
* @param {string} options.takers Optional object of takers (defaults to `takeEvery`). Can be string `takeLatest`.
15
* @param {string} options.sagaApi A `sagaApi` instance
16
* @arg {function} extend A function to pass actions and add extra sagas
17
*
18
* @return {function} Function that accepts redux actions object
19
*/
20
​
21
declare const crudSaga: (opts: SagaApiOpts, extend: ExtendSagasFn) => {
22
(actions: any): {
23
[type: string]: SagaObject;
24
};
25
};
Copied!

crudInitialState

  • Creates an opinionated initial state for handling common CRUD operates
1
/**
2
* @param {object} extend Extra state parameters
3
* @returns {object} Initial state object
4
*/
5
declare const crudInitialState: {
6
(extend: anyObject): typeof extend & {
7
isFetching: boolean;
8
current: any;
9
data: anyObject;
10
error: any;
11
};
12
};
Copied!

crudReducers

  • Creates an opinionated reducer object for handling common CRUD operations
1
interface CrudReducersInstance {
2
readAll: any;
3
readOne: any;
4
create: any;
5
update: any;
6
patch: any;
7
delete: any;
8
readAllSuccess: any;
9
readOneSuccess: any;
10
createSuccess: any;
11
updateSuccess: any;
12
patchSuccess: any;
13
deleteSuccess: any;
14
setCurrent: any;
15
resetCurrent: any;
16
readAllFail: any;
17
readOneFail: any;
18
createFail: any;
19
updateFail: any;
20
patchFail: any;
21
deleteFail: any;
22
readAllDone?: any;
23
readOneDone?: any;
24
createDone?: any;
25
updateDone?: any;
26
patchDone?: any;
27
deleteDone?: any;
28
}
29
​
30
/**
31
* @param {object} extend Extra state parameters
32
* @param {boolean} done Flag to create `done` actions / reducers
33
* @returns {CrudReducersInstance} Reducer object for saga slice
34
*/
35
​
36
declare const crudReducers: (extend: anyObject, done?: boolean) => typeof extend & CrudReducersInstance;
Copied!

crudSlice

  • Creates a saga slice with opinionated CRUD functionality
1
/**
2
* @arg {object} options Options to pass to saga helper
3
* @param {string} options.name Required. Slice name
4
* @param {string} options.singular Required. Singular resource name
5
* @param {string} options.plural Required. Plural resource name
6
* @param {object} options.sagaApi Required. Saga API instance
7
* @param {object} options.initialState Extra initial state values or overrides
8
* @param {object} options.reducers Extra reducers or overrides
9
* @param {function} options.sagas Extra sagas or overrides
10
*
11
* @return {SagaSlice} A saga slice module
12
*/
13
declare const crudSlice: (opts: SagaApiOpts & ModuleOpts) => SagaSlice;
Copied!
Last modified 1yr ago