Commit 3f079d84 authored by Denys Mishunov's avatar Denys Mishunov

Logically split onInstanceDisposal into two fns

As per review
parent 7e78bc41
...@@ -151,9 +151,12 @@ export default class EditorLite { ...@@ -151,9 +151,12 @@ export default class EditorLite {
return decoratedInstance; return decoratedInstance;
}; };
static onInstanceDisposal(editor, instance, model) { static removeInstanceFromRegistry(editor, instance) {
const index = editor.instances.findIndex((inst) => inst === instance); const index = editor.instances.findIndex((inst) => inst === instance);
editor.instances.splice(index, 1); editor.instances.splice(index, 1);
}
static disposeInstanceModels(editor, instance, model) {
const instanceModel = instance.getModel() || model; const instanceModel = instance.getModel() || model;
if (!instanceModel) { if (!instanceModel) {
return; return;
...@@ -192,7 +195,6 @@ export default class EditorLite { ...@@ -192,7 +195,6 @@ export default class EditorLite {
} = {}) { } = {}) {
EditorLite.prepareInstance(el); EditorLite.prepareInstance(el);
let model;
const createEditorFn = diff ? 'createDiffEditor' : 'create'; const createEditorFn = diff ? 'createDiffEditor' : 'create';
const instance = EditorLite.convertMonacoToELInstance( const instance = EditorLite.convertMonacoToELInstance(
monacoEditor[createEditorFn].call(this, el, { monacoEditor[createEditorFn].call(this, el, {
...@@ -201,6 +203,7 @@ export default class EditorLite { ...@@ -201,6 +203,7 @@ export default class EditorLite {
}), }),
); );
let model;
if (instanceOptions.model !== null) { if (instanceOptions.model !== null) {
model = EditorLite.createEditorModel({ model = EditorLite.createEditorModel({
blobGlobalId, blobGlobalId,
...@@ -213,7 +216,8 @@ export default class EditorLite { ...@@ -213,7 +216,8 @@ export default class EditorLite {
} }
instance.onDidDispose(() => { instance.onDidDispose(() => {
EditorLite.onInstanceDisposal(this, instance, model); EditorLite.removeInstanceFromRegistry(this, instance);
EditorLite.disposeInstanceModels(this, instance, model);
}); });
EditorLite.manageDefaultExtensions(instance, el, extensions); EditorLite.manageDefaultExtensions(instance, el, extensions);
......
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