forked from nrwl/nx
/
external-api.ts
58 lines (49 loc) · 1.53 KB
/
external-api.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
58
import { getRouter } from './get-router';
import { getProjectGraphService } from './machines/get-services';
import { ProjectGraphMachineEvents } from './feature-projects/machines/interfaces';
export class ExternalApi {
_projectGraphService = getProjectGraphService();
_graphIsReady = new Promise<void>((resolve) => {
this._projectGraphService.subscribe((state) => {
if (!state.matches('idle')) {
resolve();
}
});
});
router = getRouter();
projectGraphService = {
send: (event: ProjectGraphMachineEvents) => {
this.handleLegacyProjectGraphEvent(event);
},
};
get depGraphService() {
return this.projectGraphService;
}
focusProject(projectName: string) {
this.router.navigate(`/projects/${encodeURIComponent(projectName)}`);
}
selectAllProjects() {
this.router.navigate(`/projects/all`);
}
enableExperimentalFeatures() {
localStorage.setItem('showExperimentalFeatures', 'true');
window.appConfig.showExperimentalFeatures = true;
}
disableExperimentalFeatures() {
localStorage.setItem('showExperimentalFeatures', 'false');
window.appConfig.showExperimentalFeatures = false;
}
private handleLegacyProjectGraphEvent(event: ProjectGraphMachineEvents) {
switch (event.type) {
case 'focusProject':
this.focusProject(event.projectName);
break;
case 'selectAll':
this.selectAllProjects();
break;
default:
this._graphIsReady.then(() => this._projectGraphService.send(event));
break;
}
}
}