/
fetch.effect.ts
28 lines (25 loc) · 962 Bytes
/
fetch.effect.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
import { ExtractError } from "types";
import { FetchEffectConfig } from "effect";
import { CommandInstance } from "command";
import { ClientResponseErrorType, ClientResponseType, ClientResponseSuccessType } from "client";
export class FetchEffect<T extends CommandInstance> {
constructor(public config: FetchEffectConfig<T>) {}
getEffectKey = () => {
return this.config.effectKey;
};
onTrigger = (command: T) => {
this.config.onTrigger?.(command);
};
onStart = (command: T) => {
this.config.onStart?.(command);
};
onSuccess = (response: ClientResponseSuccessType<ResponseType>, command: T) => {
this.config.onSuccess?.(response, command);
};
onError = (response: ClientResponseErrorType<ExtractError<T>>, command: T) => {
this.config.onError?.(response, command);
};
onFinished = (response: ClientResponseType<ResponseType, ExtractError<T>>, command: T) => {
this.config.onFinished?.(response, command);
};
}