8000 fix: initView and load extensions after workbench be ready by wewoor · Pull Request #853 · DTStack/molecule · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: initView and load extensions after workbench be ready #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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