-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkMixin.ts
54 lines (48 loc) · 1.43 KB
/
NetworkMixin.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
import { INetworkMixin, RequestStage } from '../interfaces/index'
export function applyNetworkMixin(base: any): any {
/**
* Expecting this.stage in runtime
*/
class NetworkMixin extends base implements INetworkMixin {
get isRequestOverrideAvailable() {
return [
// RequestStage.initial,
RequestStage.gotRequest,
].includes(this.stage);
}
get isResponseCollecting() {
return this.stage === RequestStage.sentRequest;
}
get isResponseCollected() {
return [
RequestStage.gotResponse,
RequestStage.sentResponse,
].includes(this.stage);
}
get isResponseOverrideAvailable() {
return [
RequestStage.gotRequest,
RequestStage.sentRequest,
RequestStage.gotResponse,
].includes(this.stage);
}
get isResponseFinished() {
return [
RequestStage.sentResponse,
RequestStage.closed,
].includes(this.stage);
}
// todo: rework relations
get json() {
try {
return JSON.parse(this.body);
} catch (e) {
return undefined;
}
}
set json(obj: any) {
this.body = JSON.stringify(obj)
}
}
return NetworkMixin;
}