-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlivesync-process-data-service.ts
57 lines (49 loc) · 1.89 KB
/
livesync-process-data-service.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
import { IDictionary } from "../common/declarations";
import { injector } from "../common/yok";
import * as _ from "lodash";
export class LiveSyncProcessDataService implements ILiveSyncProcessDataService {
protected processes: IDictionary<ILiveSyncProcessData> = {};
public persistData(
projectDir: string,
deviceDescriptors: ILiveSyncDeviceDescriptor[],
platforms: string[]
): void {
this.processes[projectDir] =
this.processes[projectDir] || Object.create(null);
this.processes[projectDir].actionsChain =
this.processes[projectDir].actionsChain || Promise.resolve();
this.processes[projectDir].currentSyncAction = this.processes[
projectDir
].actionsChain;
this.processes[projectDir].isStopped = false;
this.processes[projectDir].platforms = platforms;
const currentDeviceDescriptors = this.getDeviceDescriptors(projectDir);
this.processes[projectDir].deviceDescriptors = _.uniqBy(
currentDeviceDescriptors.concat(deviceDescriptors),
"identifier"
);
}
public getPersistedData(projectDir: string): ILiveSyncProcessData {
return this.processes[projectDir];
}
public getDeviceDescriptors(projectDir: string): ILiveSyncDeviceDescriptor[] {
const liveSyncProcessesInfo =
this.processes[projectDir] || <ILiveSyncProcessData>{};
const currentDescriptors = liveSyncProcessesInfo.deviceDescriptors;
return currentDescriptors || [];
}
public hasDeviceDescriptors(projectDir: string): boolean {
const deviceDescriptors = this.getDeviceDescriptors(projectDir);
return !!deviceDescriptors.length;
}
public getAllPersistedData() {
return this.processes;
}
public getPlatforms(projectDir: string): string[] {
const liveSyncProcessesInfo =
this.processes[projectDir] || <ILiveSyncProcessData>{};
const currentPlatforms = liveSyncProcessesInfo.platforms;
return currentPlatforms || [];
}
}
injector.register("liveSyncProcessDataService", LiveSyncProcessDataService);