Skip to content

Commit

Permalink
fix: prevent multiply calls of render function (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
mortalYoung authored Jun 22, 2022
1 parent 6a8e109 commit b34a8f2
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/services/instanceService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class InstanceService
defaultLocale: 'en',
};

private rendered = false;

constructor(config: IConfigProps) {
super();
if (config.defaultLocale) {
Expand Down Expand Up @@ -59,25 +61,28 @@ export default class InstanceService
};

public render = (workbench: ReactElement) => {
this.emit(InstanceHookKind.beforeInit);

// get all locales including builtin and custom locales
const [languages, others] = molecule.extension.splitLanguagesExts(
this._config.extensions
);
this.initialLocaleService(languages);

// 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.monacoService.initWorkspace(molecule.layout.container!);
if (!this.rendered) {
this.emit(InstanceHookKind.beforeInit);

// get all locales including builtin and custom locales
const [languages, others] = molecule.extension.splitLanguagesExts(
this._config.extensions
);
this.initialLocaleService(languages);

// 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.monacoService.initWorkspace(molecule.layout.container!);
this.rendered = true;
}

return workbench;
};
Expand Down

0 comments on commit b34a8f2

Please sign in to comment.