Commit a6a7a0e1 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Make RepoEditor an async component to load monaco before mounting

parent 98ad6706
...@@ -9,7 +9,7 @@ import RepoCommitSection from './repo_commit_section.vue'; ...@@ -9,7 +9,7 @@ import RepoCommitSection from './repo_commit_section.vue';
import RepoTabs from './repo_tabs.vue'; import RepoTabs from './repo_tabs.vue';
import RepoFileButtons from './repo_file_buttons.vue'; import RepoFileButtons from './repo_file_buttons.vue';
import RepoBinaryViewer from './repo_binary_viewer.vue'; import RepoBinaryViewer from './repo_binary_viewer.vue';
import RepoEditor from './repo_editor.vue'; import RepoEditor from './repo_editor';
import RepoMiniMixin from './repo_mini_mixin'; import RepoMiniMixin from './repo_mini_mixin';
function initRepo() { function initRepo() {
......
<script>
/* global monaco */ /* global monaco */
import Store from './repo_store'; import Store from './repo_store';
import Helper from './repo_helper'; import Helper from './repo_helper';
...@@ -7,28 +6,28 @@ import monacoLoader from './monaco_loader'; ...@@ -7,28 +6,28 @@ import monacoLoader from './monaco_loader';
const RepoEditor = { const RepoEditor = {
data: () => Store, data: () => Store,
template: '<div id="ide"></div>',
mounted() { mounted() {
monacoLoader(['vs/editor/editor.main'], () => { const monacoInstance = this.monaco.editor.create(this.$el, {
const monacoInstance = monaco.editor.create(this.$el, { model: null,
model: null, readOnly: true,
readOnly: true, contextmenu: false,
contextmenu: false, });
});
Store.monacoInstance = monacoInstance; Store.monacoInstance = monacoInstance;
this.addMonacoEvents(); this.addMonacoEvents();
Helper.getContent().then(() => { Helper.getContent().then(() => {
this.showHide(); this.showHide();
if (this.blobRaw === '') return; if (this.blobRaw === '') return;
const newModel = monaco.editor.createModel(this.blobRaw, 'plaintext'); const newModel = this.monaco.editor.createModel(this.blobRaw, 'plaintext');
this.monacoInstance.setModel(newModel); this.monacoInstance.setModel(newModel);
}).catch(Helper.loadingError); }).catch(Helper.loadingError);
});
}, },
methods: { methods: {
...@@ -98,18 +97,23 @@ const RepoEditor = { ...@@ -98,18 +97,23 @@ const RepoEditor = {
this.monacoInstance.setModel(null); this.monacoInstance.setModel(null);
const languages = monaco.languages.getLanguages(); const languages = this.monaco.languages.getLanguages();
const languageID = Helper.getLanguageIDForFile(this.activeFile, languages); const languageID = Helper.getLanguageIDForFile(this.activeFile, languages);
const newModel = monaco.editor.createModel(this.blobRaw, languageID); const newModel = this.monaco.editor.createModel(this.blobRaw, languageID);
this.monacoInstance.setModel(newModel); this.monacoInstance.setModel(newModel);
}, },
}, },
}; };
export default RepoEditor; function asyncLoadRepoEditor() {
</script> return new Promise((resolve) => {
monacoLoader(['vs/editor/editor.main'], () => {
Store.monaco = monaco;
resolve(RepoEditor);
});
});
}
<template> export default asyncLoadRepoEditor;
<div id="ide"></div>
</template>
...@@ -3,6 +3,7 @@ import RepoHelper from './repo_helper'; ...@@ -3,6 +3,7 @@ import RepoHelper from './repo_helper';
const RepoStore = { const RepoStore = {
ideEl: {}, ideEl: {},
monaco: {},
monacoInstance: {}, monacoInstance: {},
service: '', service: '',
editor: '', editor: '',
......
import Vue from 'vue'; import Vue from 'vue';
import repoEditor from '~/repo/repo_editor.vue'; import repoEditor from '~/repo/repo_editor';
describe('RepoEditor', () => { describe('RepoEditor', () => {
function createComponent() { function createComponent() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment