blob: c60bba4293ade0418bf3fb09f665c607d2a14411 (
plain)
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
|
import { debounce } from 'lodash';
import eventHub from '~/ide/eventhub';
import terminalSyncModule from '../modules/terminal_sync';
import { isEndingStatus, isRunningStatus } from '../modules/terminal/utils';
const UPLOAD_DEBOUNCE = 200;
/**
* Registers and controls the terminalSync vuex module based on IDE events.
*
* - Watches the terminal session status state to control start/stop.
* - Listens for file change event to control upload.
*/
export default function createMirrorPlugin() {
return store => {
store.registerModule('terminalSync', terminalSyncModule());
const upload = debounce(() => {
store.dispatch(`terminalSync/upload`);
}, UPLOAD_DEBOUNCE);
const stop = () => {
store.dispatch(`terminalSync/stop`);
eventHub.$off('ide.files.change', upload);
};
const start = () => {
store
.dispatch(`terminalSync/start`)
.then(() => {
eventHub.$on('ide.files.change', upload);
})
.catch(() => {
// error is handled in store
});
};
store.watch(
x => x.terminal && x.terminal.session && x.terminal.session.status,
val => {
if (isRunningStatus(val)) {
start();
} else if (isEndingStatus(val)) {
stop();
}
},
);
};
}
|