Welcome to mirror list, hosted at ThFree Co, Russian Federation.

setup.js « editor « modules « stores « ide « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5899706e38aa89ed9a7d7143b7d58104161f140f (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
import { commitActionTypes } from '~/ide/constants';
import eventHub from '~/ide/eventhub';

const removeUnusedFileEditors = (store) => {
  Object.keys(store.state.editor.fileEditors)
    .filter((path) => !store.state.entries[path])
    .forEach((path) => store.dispatch('editor/removeFileEditor', path));
};

export const setupFileEditorsSync = (store) => {
  eventHub.$on('ide.files.change', ({ type, ...payload } = {}) => {
    // Do nothing on file update because the file tree itself hasn't changed.
    if (type === commitActionTypes.update) {
      return;
    }

    if (type === commitActionTypes.move) {
      store.dispatch('editor/renameFileEditor', payload);
    } else {
      // The file tree has changed, but the specific change is not known.
      removeUnusedFileEditors(store);
    }
  });
};