Skip to content

Commit

Permalink
fix: initView and load extensions after workbench be ready (DTStack#853
Browse files Browse the repository at this point in the history
)

* fix: only alow to create monacoInstance once

* fix: initView and load extensions after workbench be ready
  • Loading branch information
wewoor authored Jun 12, 2023
1 parent 122eff9 commit 567f629
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
14 changes: 8 additions & 6 deletions src/components/monaco/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ export class MonacoEditor extends PureComponent<IMonacoEditorProps> {

componentDidMount() {
const { options = {}, override, editorInstanceRef } = this.props;
this.monacoInstance = this.monacoService?.create(
this.monacoDom,
options,
override
);
editorInstanceRef?.(this.monacoInstance);
if (!this.monacoInstance) {
this.monacoInstance = this.monacoService?.create(
this.monacoDom,
options,
override
);
editorInstanceRef?.(this.monacoInstance);
}
}

componentDidUpdate(prevProps) {
Expand Down
11 changes: 1 addition & 10 deletions src/provider/__tests__/__snapshots__/molecule.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1058,16 +1058,7 @@ dmlldzJfOV8xNjM4ODQ4MDI1NDI2MTE4Ml8zOF9bMF0TNSl1AAAAAElFTkSuQmCC"
<div
class="keybindings"
>
<ul>
<li
class="keys"
>
<span>
Command Palette
</span>
<span />
</li>
</ul>
<ul />
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/services/__tests__/instanceService.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';
import { defaultExtensions } from 'mo/extensions';
import InstanceService from '../instanceService';
import { render } from '@testing-library/react';
import { LayoutEvents } from 'mo/model/workbench/layout';
import molecule from 'mo';

describe('The InstanceService', () => {
test('Constuctor with default config', () => {
Expand Down Expand Up @@ -39,6 +41,7 @@ describe('The InstanceService', () => {
const mockFn = jest.fn();
instance.onBeforeInit(mockFn);
instance.onBeforeLoad(mockFn);
molecule.layout.emit(LayoutEvents.OnWorkbenchDidMount);
instance.render(<div>123</div>);

expect(mockFn).toBeCalledTimes(2);
Expand Down
32 changes: 18 additions & 14 deletions src/services/instanceService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,26 @@ export default class InstanceService
StatusBarController,
];

// resolve all controllers, and call `initView` to inject initial values into services
Object.keys(controllers).forEach((key) => {
const module = controllers[key];
const controller = container.resolve<Controller>(module);
controller.initView?.();
});

this.emit(InstanceHookKind.beforeLoad);
molecule.extension.load(others);

molecule.layout.onWorkbenchDidMount(() => {
molecule.monacoService.initWorkspace(
molecule.layout.container!
);
if (!this.rendered) {
molecule.monacoService.initWorkspace(
molecule.layout.container!
);

// resolve all controllers, and call `initView` to inject initial values into services
Object.keys(controllers).forEach((key) => {
const module = controllers[key];
const controller =
container.resolve<Controller>(module);
controller.initView?.();
});

this.emit(InstanceHookKind.beforeLoad);
molecule.extension.load(others);

this.rendered = true;
}
});
this.rendered = true;
}

return workbench;
Expand Down

0 comments on commit 567f629

Please sign in to comment.