/
request.effect.types.ts
44 lines (41 loc) · 1.5 KB
/
request.effect.types.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
import { RequestInstance } from "request";
import { ResponseReturnErrorType, ResponseReturnType, ResponseReturnSuccessType } from "adapter";
import { RequestEffect } from "effect";
import { ExtractAdapterType, ExtractErrorType, ExtractResponseType } from "types";
export type RequestEffectLifecycle = "trigger" | "start" | "success" | "error" | "finished";
export type RequestEffectInstance = RequestEffect<RequestInstance>;
export type RequestEffectOptionsType<T extends RequestInstance> = {
/**
* It should match effectKey on the request for which given effect should be triggered.
*/
effectKey: string;
/**
* Callback that will be executed when request gets triggered
*/
onTrigger?: (request: RequestInstance) => void;
/**
* Callback that will be executed when request starts
*/
onStart?: (request: RequestInstance) => void;
/**
* Callback that will be executed when response is successful
*/
onSuccess?: (
response: ResponseReturnSuccessType<ExtractResponseType<T>, ExtractAdapterType<T>>,
request: RequestInstance,
) => void;
/**
* Callback that will be executed when response is failed
*/
onError?: (
response: ResponseReturnErrorType<ExtractErrorType<T>, ExtractAdapterType<T>>,
request: RequestInstance,
) => void;
/**
* Callback that will be executed when response is finished
*/
onFinished?: (
response: ResponseReturnType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>,
request: RequestInstance,
) => void;
};